forked from 1b-agent/fieldcraft-upstream
Engine: crash reports, a log file and bug report drafts (#107)
crash: a panic hook and a locked per-run command journal (adapted from SolidCraft's crash reports). A panic in a command becomes a report with the model from before it and the command; one outside commands, or an unclean exit found at the next start (abort, segfault, a crash in a graphics driver, a kill: what #248 needs), a report with the model the journal starts from (autosave, file or a copy) and the commands since, the last control request and the dead run's log lines. Reports are bounded, deduplicated by signature and replayable (crash::replay, with writes confined to a scratch folder). The crash folder follows the automation temp area in --control and CI runs. logfile: a small size-rotated file logger behind the log facade. bug_report: GitHub bug-form drafts. Version, OS and what happened by default, home folder shown as ~; the command journal only with Share my session, the model only with Include the model as well; a session too long for the link becomes a file to attach and the clipboard text. Commands: diagnostics.crash_reports, diagnostics.crash_report, diagnostics.bug_report (Tools › Help, with its icon) and diagnostics.crash_test (FIELDCRAFT_CRASH_TEST=1 only). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UhhZMBTviDQxZvwnyP89fo
This commit is contained in:
1 parent
3d51bde9dd
commit
080ff048c6
15 files changed
+2200
-2
No files matched your search
@@ -13,8 +13,11 @@
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
pub mod autosave;
|
||||
pub mod bug_report;
|
||||
pub mod catalogue;
|
||||
pub mod cmd;
|
||||
pub mod crash;
|
||||
pub mod logfile;
|
||||
|
||||
pub use cmd::analytic_surfaces;
|
||||
pub use cmd::replace::{MESHERS, Replacement, replacement};
|
||||
@@ -244,6 +247,9 @@ pub struct Session {
|
||||
pub view: fieldcraft_io::View,
|
||||
/// The view as last saved (or opened): a change to it is unsaved too.
|
||||
saved_view: fieldcraft_io::View,
|
||||
/// This is the app's own model: its top-level commands go into the crash journal
|
||||
/// ([`crash`]), so an unclean exit can be replayed. Off for scratch sessions and tests.
|
||||
pub crash_journal: bool,
|
||||
}
|
||||
|
||||
impl Session {
|
||||
@@ -256,6 +262,9 @@ impl Session {
|
||||
// Session commands (open, save, undo, redo) change the session only in their last step,
|
||||
// after everything that can fail, so they need no copy of the model to restore.
|
||||
let before = (spec.kind == CommandKind::Model).then(|| (self.snapshot(), self.document()));
|
||||
let scope = crash::Scope::enter();
|
||||
let journaled = crash::command_begin(&scope, self, id, params);
|
||||
let (revision, opened) = (self.revision, self.opened);
|
||||
let outcome = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| (spec.run)(self, params)));
|
||||
let result = match outcome {
|
||||
Ok(Err(EngineError::Param(p))) => Err(EngineError::Param(match spec.form {
|
||||
@@ -285,6 +294,8 @@ impl Session {
|
||||
cmd::view::forget_missing(self);
|
||||
}
|
||||
}
|
||||
drop(scope);
|
||||
crash::command_done(self, journaled, self.revision != revision || self.opened != opened, id, params, &result);
|
||||
result
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user