Never crash: last-resort guard around command execution, and a logging panic hook

Session::execute runs every command (UI, CLI, control channel, MCP, scripts; file import,
export and save are commands too) through guard::guarded, which catch_unwinds a panic that
escapes the command and returns EngineError::Other("command `x` failed with an internal error
(...); it was stopped and your project is still open"). Edits work on a copy of the project, so
a command that panics mid-edit leaves the project untouched. The desktop app also installs a
panic hook that logs every panic through the app logger (then runs the default hook).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Thomas
2026-10-04 13:27:33 -04:00
co-authored by Claude Opus 5.5
parent 10644a83aa
commit 6144ca0804
4 changed files with 79 additions and 1 deletions
+3 -1
View File
@@ -14,6 +14,7 @@ pub mod commands;
pub mod config;
pub mod demo;
pub mod footage_check;
pub mod guard;
pub mod history;
pub mod jobs;
pub mod learn;
@@ -490,7 +491,8 @@ impl Session {
return Err(EngineError::Disabled(id.to_string(), why));
}
}
let r = (spec.run)(self, &params)?;
// Last-resort guard: a panicking command reports an error instead of crashing the app.
let r = guard::guarded(&format!("command `{id}`"), || (spec.run)(self, &params))?;
self.learn_observe(id, &params);
if spec.journal {
self.journal.push((id.to_string(), params));