Skip to main content

Module crash

Module crash 

Source
Expand description

Crash reports, written on the machine and offered on the next start. Nothing is sent anywhere.

Experimental: may change in any release (docs/stability.md).

CrashPlugin marks the session as running (session-<pid>.json in the crash directory, <state>/crashes) and installs a panic hook (chained to the one before it). A panic writes panic-<pid>.json: the application’s name and version, the OS and its release, the thread, the message, where, a backtrace, the last log lines (from the app’s crate::logs) and the tail of the host’s journal. A clean exit (the app.exit step) takes the marker and the panics of the session away: a panic a fault boundary caught does not make a report.

On the next start, a marker left by a session that is gone means it did not end cleanly: its panics, or a report saying it ended without closing (killed, out of memory, a crash in native code) with the last lines of its log file, become report-<time>-<pid>.json, and the step runs (ADR 0011):

  • crash.report: a report to offer, { "path", "report" }. By default the report (with whatever a before-hook added by redirecting it) is written back and offered in a toast that stays, with a button showing the file (crash.reveal). An application adds data with a before-hook, sends it with an after-hook (its own service, after asking the user), or replaces it with a dialog of its own.

The reports stay until dismissed (crash.dismiss, Crashes).

use egui_pop_api::App;
use egui_pop_api::toasts::{TOASTS, ToastsPlugin};
use egui_pop_platform::crash::{self, CrashPlugin, Report};

let dir = std::env::temp_dir().join(format!("egui-pop-crash-doc-{}", std::process::id()));
// A session that died: its marker and its panic stay.
crash::simulate(&dir, 4_000_000, &Report::panic("Demo", "1.0", "index out of bounds"))
    .unwrap();
let ctx = egui::Context::default();
let mut app = App::builder()
    .plugin(ToastsPlugin)
    .plugin(CrashPlugin::new("Demo", "1.0").dir(&dir).hook(false))
    .build(&ctx)
    .unwrap();
app.logic(&ctx);
let toasts = app.handle().service(&TOASTS).unwrap();
assert!(toasts.shown()[0].toast.text.contains("closed unexpectedly"));

Structs§

CrashPlugin
Crash reports, as a plugin (see the module).
Crashes
The reports on this machine, as a service.
Panic
One panic.
Report
A crash report.

Constants§

CMD_DISMISS
Deletes a report ({ "path" }).
CMD_REVEAL
Shows a report’s file ({ "path" }).
CRASHES
The reports, as a service.
JOURNAL_TAIL
How many journal events a report quotes.
LOG_TAIL
How many log lines a report quotes.
PLUGIN
The plugin’s id.
STEP_REPORT
A report to offer: { "path", "report" }.

Functions§

collect
Turns the sessions that died into reports: returns the reports’ files, newest last.
simulate
Leaves what a session that died leaves: its marker, and its panic when report has one (for tests and the gallery; pid should name no running process).