Skip to content

Commit

Permalink
fix(cli): properly exit with code 0 on panic when running with bun (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Aug 13, 2024
1 parent f8d658e commit 41c7a66
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-cli-panic-bun.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tauri-apps/cli": patch:bug
---

Exit with code 1 if a panic occurs when running the CLI with `bun`.
29 changes: 23 additions & 6 deletions tooling/cli/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,29 @@ pub fn run(args: Vec<String>, bin_name: Option<String>, callback: JsFunction) ->

// we need to run in a separate thread so Node.js consumers
// can do work while `tauri dev` is running.
std::thread::spawn(move || match tauri_cli::try_run(args, bin_name) {
Ok(_) => function.call(Ok(true), ThreadsafeFunctionCallMode::Blocking),
Err(e) => function.call(
Err(Error::new(Status::GenericFailure, format!("{:#}", e))),
ThreadsafeFunctionCallMode::Blocking,
),
std::thread::spawn(move || {
let res = match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
tauri_cli::try_run(args, bin_name)
})) {
Ok(t) => t,
Err(e) => {
return function.call(
Err(Error::new(
Status::GenericFailure,
"Tauri CLI unexpected panic",
)),
ThreadsafeFunctionCallMode::Blocking,
);
}
};

match res {
Ok(_) => function.call(Ok(true), ThreadsafeFunctionCallMode::Blocking),
Err(e) => function.call(
Err(Error::new(Status::GenericFailure, format!("{:#}", e))),
ThreadsafeFunctionCallMode::Blocking,
),
}
});

Ok(())
Expand Down

0 comments on commit 41c7a66

Please sign in to comment.