gitbutlerapp/gitbutler · critical

panic while executing

Error message

panic while executing `{}` on thread '{}' ({}) at {}: {}

panic backtrace:
{}

What it means

`panic_payload_to_anyhow` converts a caught Rust panic into an `anyhow::Error`. When a backtrace snapshot is available, it formats a detailed message naming the function that panicked, the thread name/id, the panic location, and the captured backtrace. It surfaces when code executed through the library's panic-capture hook panicked.

Solutions

  1. Read the panic location and backtrace in the message to find the panicking code
  2. Fix the underlying panic (unwrap/expect/assertion) in the identified function
  3. If the panic payload was not a string, instrument the code to panic with a descriptive message
  4. Update the library if the panic originates in a known fixed bug
Defensive patterns

Strategy: try-catch

Try / catch

// treat returned anyhow::Error as panic report
match wrapped_call() {
    Ok(v) => v,
    Err(e) => {
        let msg = format!("{e:#}");
        if msg.contains("panic while executing") { log_panic_report(&msg); }
        return Err(e);
    }
}

Prevention

When it happens

Trigger: Any wrapped/intercepted function call panics and the panic hook captured a backtrace snapshot; the panic payload is not a string, in which case 'panic payload was not a string' is substituted.

Common situations: A bug in user callback code or library internals (unwrap on None, index out of bounds, assertion failure) executed inside a panic-captured context, e.g. in API handlers or background threads.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/2a3852655018fafc. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-api/src/panic_capture.rs:63

/// back to payload-derived message plus a backtrace captured during conversion.
///
/// Assumes that the panic hook has been installed via [`install_panic_hook()`], or
/// else the panic message will not have a backtrace.
pub(crate) fn panic_payload_to_anyhow(
    function_name: &'static str,
    panic_payload: Box<dyn Any + Send + 'static>,
) -> anyhow::Error {
    let payload_message = panic_payload_message(panic_payload.as_ref());
    let snapshot = LAST_PANIC_INFO.with(|slot| slot.borrow_mut().take());

    if let Some(snapshot) = snapshot {
        let panic_message = snapshot
            .payload_message
            .as_deref()
            .or(payload_message.as_deref())
            .unwrap_or("panic payload was not a string");
        let panic_location = snapshot.location.as_deref().unwrap_or("<unknown location>");
        anyhow::anyhow!(
            "panic while executing `{}` on thread '{}' ({}) at {}: {}\n\npanic backtrace:\n{}",
            function_name,
            snapshot.thread_name,
            snapshot.thread_id,
            panic_location,
            panic_message,
            snapshot.backtrace
        )
    } else {
        let panic_message = payload_message
            .as_deref()
            .unwrap_or("panic payload was not a string");
        anyhow::anyhow!(
            "panic while executing `{}`: {}\n\npanic backtrace unavailable from hook; conversion backtrace:\n{}",
            function_name,
            panic_message,
            std::backtrace::Backtrace::force_capture()
        )

View on GitHub (pinned to 58e5313667)