MCPcopy Create free account
hub / github.com/GCWing/BitFun / setup_panic_hook

Function setup_panic_hook

src/apps/desktop/src/lib.rs:1488–1561  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1486}
1487
1488fn setup_panic_hook() {
1489 std::panic::set_hook(Box::new(move |panic_info| {
1490 let thread = std::thread::current();
1491 let thread_name = thread.name().map(str::to_string);
1492 let thread_id = format!("{:?}", thread.id());
1493 let is_main_thread = thread_name.as_deref() == Some("main") || thread_name.is_none(); // unnamed threads in simple test contexts
1494
1495 let location = panic_info
1496 .location()
1497 .map(|l| format!("{}:{}:{}", l.file(), l.line(), l.column()))
1498 .unwrap_or_else(|| "unknown location".to_string());
1499
1500 let message = panic_info
1501 .payload()
1502 .downcast_ref::<&str>()
1503 .copied()
1504 .or_else(|| {
1505 panic_info
1506 .payload()
1507 .downcast_ref::<String>()
1508 .map(String::as_str)
1509 })
1510 .unwrap_or("unknown panic message");
1511
1512 log::error!(
1513 "Application panic at {} (thread={:?}, id={}, main={}): {}",
1514 location,
1515 thread_name,
1516 thread_id,
1517 is_main_thread,
1518 message,
1519 );
1520 crate::crash_diagnostics::write_panic_report(
1521 location.clone(),
1522 message.to_string(),
1523 thread_name.clone(),
1524 thread_id,
1525 );
1526
1527 // Known wry bug: WKWebView.URL() returns nil after navigating to an
1528 // invalid address, causing url_from_webview to panic on unwrap().
1529 // This is non-fatal — the webview is still alive — so we log and
1530 // continue instead of killing the process.
1531 // See: https://github.com/tauri-apps/wry/pull/1554
1532 if location.contains("wry") && location.contains("wkwebview") {
1533 log::warn!("Suppressed non-fatal wry/wkwebview panic, application continues");
1534 return;
1535 }
1536
1537 if message.contains("WSAStartup") || message.contains("10093") || message.contains("hyper")
1538 {
1539 log::error!("Network-related crash detected, possible solutions:");
1540 log::error!(" 1) Restart the application");
1541 log::error!(" 2) Check Windows network service status");
1542 log::error!(" 3) Run as administrator");
1543 }
1544
1545 // ── Recovery strategy ──────────────────────────────────────────

Callers 1

runFunction · 0.85

Calls 6

write_panic_reportFunction · 0.85
nameMethod · 0.45
payloadMethod · 0.45
cloneMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected