Skip to content

Commit 4148ab6

Browse files
Codexbranchseer
andauthored
fix(session): print errors in Session::main and return ExitStatus
Co-authored-by: branchseer <3612422+branchseer@users.noreply.github.com>
1 parent a88412b commit 4148ab6

2 files changed

Lines changed: 26 additions & 21 deletions

File tree

crates/vite_task/src/session/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,20 @@ impl<'a> Session<'a> {
244244

245245
/// Primary entry point for CLI usage. Plans and executes the given command.
246246
///
247-
/// # Errors
248-
///
249-
/// Returns an error if planning or execution fails.
247+
/// This function prints user-facing errors itself and returns an exit status
248+
/// code only. This allows downstream CLIs (like `vp run`) to simply
249+
/// `std::process::exit(i32::from(status.0))` without duplicating error
250+
/// reporting.
250251
#[tracing::instrument(level = "debug", skip_all)]
251-
pub async fn main(mut self, command: Command) -> anyhow::Result<ExitStatus> {
252+
pub async fn main(mut self, command: Command) -> ExitStatus {
252253
match self.main_inner(command).await {
253-
Ok(()) => Ok(ExitStatus::SUCCESS),
254-
Err(SessionError::EarlyExit(status)) => Ok(status),
255-
Err(SessionError::Anyhow(err)) => Err(err),
254+
Ok(()) => ExitStatus::SUCCESS,
255+
Err(SessionError::EarlyExit(status)) => status,
256+
#[expect(clippy::print_stderr, reason = "top-level error reporting")]
257+
Err(SessionError::Anyhow(err)) => {
258+
eprintln!("Error: {err:?}");
259+
ExitStatus::FAILURE
260+
}
256261
}
257262
}
258263

crates/vite_task_bin/src/main.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ use vite_task::{Command, ExitStatus, Session};
33
use vite_task_bin::OwnedSessionConfig;
44

55
fn main() -> ! {
6-
let exit_code: i32 =
7-
tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap().block_on(async {
8-
match run().await {
9-
Ok(status) => i32::from(status.0),
10-
#[expect(clippy::print_stderr, reason = "top-level error reporting")]
11-
Err(err) => {
12-
eprintln!("Error: {err:?}");
13-
1
14-
}
15-
}
16-
});
6+
let exit_code: i32 = tokio::runtime::Builder::new_multi_thread()
7+
.enable_all()
8+
.build()
9+
.unwrap()
10+
.block_on(async { i32::from(run().await.0) });
1711

1812
std::process::exit(exit_code);
1913
}
2014

21-
async fn run() -> anyhow::Result<ExitStatus> {
15+
async fn run() -> ExitStatus {
2216
let args = Command::parse();
2317
let mut owned_config = OwnedSessionConfig::default();
24-
let session = Session::init(owned_config.as_config())?;
25-
session.main(args).await
18+
match Session::init(owned_config.as_config()) {
19+
Ok(session) => session.main(args).await,
20+
#[expect(clippy::print_stderr, reason = "top-level error reporting")]
21+
Err(err) => {
22+
eprintln!("Error: {err:?}");
23+
ExitStatus::FAILURE
24+
}
25+
}
2626
}

0 commit comments

Comments
 (0)