po4yka/rust-skills / skills/rust-panic-safety
rust-panic-safety
VerifiedUse when guarding an extern "C", extern "system", or JNI entry point with catch_unwind, choosing panic = "unwind" or "abort", installing a panic hook, disposing of a panic payload, fixing an UnwindSafe bound with AssertUnwindSafe, or triaging an abort such as "panic in a function that cannot unwind". Also use when a panic can escape a foreign callback, spawned task, thread, or Drop, or when replacing unwrap or expect on an FFI-reachable path. Owns the panic policy at a C ABI boundary.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 11.5 KB |
| references/boundary-patterns.md | markdown | 16.4 KB |
| references/drop-guard.md | markdown | 2.0 KB |
| references/jni-boundary.md | markdown | 8.4 KB |
| references/panic-hook.md | markdown | 3.4 KB |
| references/panic-strategy.md | markdown | 2.2 KB |
| references/unwind-state.md | markdown | 2.3 KB |
| references/unwrap-audit.md | markdown | 10.0 KB |
references/panic-hook.md
View on GitHub# Privacy-safe panic hook
Read this file when you install or review a panic hook. It holds the catalog's single copy of
the report block; other skills point here.
A guard that returns the panic code with no other signal turns a bug into a mystery. Install a
hook that emits one bounded structured record. Do not inspect the panic payload in shipped code:
it can contain input data, paths, identifiers, or secrets. Rules:
- Let the application-owned outermost Rust FFI bootstrap own `set_hook`. An embedded component
exposes a redacted handler and never replaces an unknown process-global hook.
- Do not chain the default hook in a shipped embedded process. It formats the payload and file
path. Keep it only in a local host binary whose stderr is not forwarded to telemetry.
- Map the file path to a closed site code. Emit only that code plus the bounded numeric line and
column. Do not format `PanicHookInfo`, emit a file path, or capture a backtrace into a shipped
platform log.
- The hook must not panic. A panic inside the hook aborts the process with `thread panicked
while processing panic. aborting.` (Rust 1.99.1).
- Install the hook before any task or thread starts. A panic that crosses a task boundary loses
its location, and only the hook still has it.
- `PanicHookInfo` needs Rust 1.81. Below MSRV 1.81, the hook argument is `PanicInfo`, with the
same `location()`.
```rust
#[derive(Clone, Copy)]
enum PanicSite {
Boundary,
Engine,
Unknown,
}
fn classify_site(file: &str) -> PanicSite {
// Cargo passes a workspace member as `<member-dir>/src/...` and a registry
// dependency as an absolute path, so match a segment, not a prefix. The path
// keeps the separator of the build host: a Windows build gives `src\boundary\`.
if file.contains("src/boundary/") || file.contains(r"src\boundary\") {
PanicSite::Boundary
} else if file.contains("src/engine/") || file.contains(r"src\engine\") {
PanicSite::Engine
} else {
PanicSite::Unknown
}
}
pub fn report_panic(info: &std::panic::PanicHookInfo<'_>) {
let (site, line, column) = info
.location()
.map(|location| {
(
classify_site(location.file()),
location.line(),
location.column(),
)
})
.unwrap_or((PanicSite::Unknown, 0, 0));
write_platform_panic("rust_panic", site, line, column);
}
// The application-owned outermost Rust FFI bootstrap owns the process-global
// hook and statically composes every component handler once during startup.
pub fn install_bootstrap_panic_hook() {
std::panic::set_hook(Box::new(|info| {
report_panic(info);
report_other_library_panics(info);
}));
}
```
- `write_platform_panic` stands for the platform sink. The `rust-observability` skill covers
the sink; the hook emits only bounded structured fields and never formats `PanicHookInfo`,
its payload, or a backtrace.
- `report_other_library_panics` stands for the redacted handlers that embedded components
expose. The bootstrap composes them here once.
- The bootstrap can install from its `JNI_OnLoad` or from one explicit init export, after it
composes the component handlers.
- For a message or a backtrace, use `RUST_BACKTRACE=full` in a local host repro. Symbolicate a
tombstone or crash report offline against the exact unstripped binary for an app process.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |