Skip to main content

Crate panic_as_error

Crate panic_as_error 

Source
Expand description

Catching a panic as a value that names where it began.

A panic turned into an Err at the nearest catch lets the caller’s own failure path run: the rollback or cleanup it does on Err, which an unwind would skip. caught catches a panic in a future, and caught_sync in a synchronous call. Each returns a Bug that holds the text the panic carried, the operation the work was doing, and the SourceLocation where the panic began, which a panic’s payload does not hold.

Work nobody waits for hands its bug to a BugSink instead, through report, and an error that holds a bug says so through CarriesBug. locks holds the helpers that take a lock whose holder panicked.

Modules§

locks
Taking a lock whose holder may have panicked.

Structs§

Bug
Work that panicked, or that code found wrong without a panic: a bug in it, not a failure its caller can act on. The caller reports it wherever it reports its own bugs, and the call that ran the work returns it as its error.
SourceLocation
Where in the code a bug showed itself: the file, line and column of the panic, or of the code that found the bug and made it.

Enums§

BugKind
How a bug showed itself.

Traits§

BugSink
Where a bug in work nobody waits for goes: a long-lived worker, or work whose caller stopped waiting for it. The program passes its own crash reporter.
CarriesBug
An error that may carry a bug: work its call ran panicked, and the call’s error says so. Work nobody waits for reports the bug its error carries, as it reports its own panic.

Functions§

bug_of_unlocated
Make the bug for a panic’s payload when the panic began outside this crate’s catches, so the bug has no location.
catching_operation
The operation of the innermost catch of this crate’s running on this thread, or None outside every one: for the app’s own panic hook, to say what the panicking work was doing. A panic a catch inside that work handles itself, such as a task tokio runs on this thread and catches, still names it. It never panics, so a hook can call it: a panic inside a hook ends the process.
caught
Run work inline, catching a panic in any of its polls. For one message of a long-lived loop: the panic fails that message and the loop serves the next. The runtime can’t drop work that runs inline, so a panic is its only failure.
caught_sync
caught for a synchronous call: an FFI callback, a dedicated thread’s body, a Drop. Unwinding out of an extern "C" function aborts the process, so such a function catches here and answers with its own failure value.
panic_message
The text a panic carried: what panic! and expect were given, or a placeholder for a payload that is not text.
report
Hand bug to bugs. When the sink panics too, report logs that panic and stops it there, because nothing above the sink catches it.

Type Aliases§

BugSinkRef
A shared BugSink.