Skip to content

Commit 41c7a66

Browse files
authored
fix(cli): properly exit with code 0 on panic when running with bun (#10572)
1 parent f8d658e commit 41c7a66

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

.changes/fix-cli-panic-bun.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tauri-apps/cli": patch:bug
3+
---
4+
5+
Exit with code 1 if a panic occurs when running the CLI with `bun`.

tooling/cli/node/src/lib.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,29 @@ pub fn run(args: Vec<String>, bin_name: Option<String>, callback: JsFunction) ->
1414

1515
// we need to run in a separate thread so Node.js consumers
1616
// can do work while `tauri dev` is running.
17-
std::thread::spawn(move || match tauri_cli::try_run(args, bin_name) {
18-
Ok(_) => function.call(Ok(true), ThreadsafeFunctionCallMode::Blocking),
19-
Err(e) => function.call(
20-
Err(Error::new(Status::GenericFailure, format!("{:#}", e))),
21-
ThreadsafeFunctionCallMode::Blocking,
22-
),
17+
std::thread::spawn(move || {
18+
let res = match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
19+
tauri_cli::try_run(args, bin_name)
20+
})) {
21+
Ok(t) => t,
22+
Err(e) => {
23+
return function.call(
24+
Err(Error::new(
25+
Status::GenericFailure,
26+
"Tauri CLI unexpected panic",
27+
)),
28+
ThreadsafeFunctionCallMode::Blocking,
29+
);
30+
}
31+
};
32+
33+
match res {
34+
Ok(_) => function.call(Ok(true), ThreadsafeFunctionCallMode::Blocking),
35+
Err(e) => function.call(
36+
Err(Error::new(Status::GenericFailure, format!("{:#}", e))),
37+
ThreadsafeFunctionCallMode::Blocking,
38+
),
39+
}
2340
});
2441

2542
Ok(())

0 commit comments

Comments
 (0)