{"record":{"id":"2a3852655018fafc","repo":"gitbutlerapp/gitbutler","slug":"panic-while-executing-on-thread-at","errorCode":null,"errorMessage":"panic while executing `{}` on thread '{}' ({}) at {}: {}\n\npanic backtrace:\n{}","messagePattern":"panic while executing `(.+?)` on thread '(.+?)' \\((.+?)\\) at (.+?): (.+?)\n\npanic backtrace:\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/but-api/src/panic_capture.rs","lineNumber":63,"sourceCode":"/// back to payload-derived message plus a backtrace captured during conversion.\n///\n/// Assumes that the panic hook has been installed via [`install_panic_hook()`], or\n/// else the panic message will not have a backtrace.\npub(crate) fn panic_payload_to_anyhow(\n    function_name: &'static str,\n    panic_payload: Box<dyn Any + Send + 'static>,\n) -> anyhow::Error {\n    let payload_message = panic_payload_message(panic_payload.as_ref());\n    let snapshot = LAST_PANIC_INFO.with(|slot| slot.borrow_mut().take());\n\n    if let Some(snapshot) = snapshot {\n        let panic_message = snapshot\n            .payload_message\n            .as_deref()\n            .or(payload_message.as_deref())\n            .unwrap_or(\"panic payload was not a string\");\n        let panic_location = snapshot.location.as_deref().unwrap_or(\"<unknown location>\");\n        anyhow::anyhow!(\n            \"panic while executing `{}` on thread '{}' ({}) at {}: {}\\n\\npanic backtrace:\\n{}\",\n            function_name,\n            snapshot.thread_name,\n            snapshot.thread_id,\n            panic_location,\n            panic_message,\n            snapshot.backtrace\n        )\n    } else {\n        let panic_message = payload_message\n            .as_deref()\n            .unwrap_or(\"panic payload was not a string\");\n        anyhow::anyhow!(\n            \"panic while executing `{}`: {}\\n\\npanic backtrace unavailable from hook; conversion backtrace:\\n{}\",\n            function_name,\n            panic_message,\n            std::backtrace::Backtrace::force_capture()\n        )","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/panic_capture.rs#L45-L81","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the panic location and backtrace in the message to find the panicking code","Fix the underlying panic (unwrap/expect/assertion) in the identified function","If the panic payload was not a string, instrument the code to panic with a descriptive message","Update the library if the panic originates in a known fixed bug"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// treat returned anyhow::Error as panic report\nmatch wrapped_call() {\n    Ok(v) => v,\n    Err(e) => {\n        let msg = format!(\"{e:#}\");\n        if msg.contains(\"panic while executing\") { log_panic_report(&msg); }\n        return Err(e);\n    }\n}","preventionTips":["Avoid unwrap/expect in wrapped callback code","Panic with descriptive string messages","Keep the panic hook installed early in process startup","Set RUST_BACKTRACE=1 for richer reports"],"tags":["panic","rust","internal-error"],"backgroundTag":"internal-invariant-violation","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}