Skip to main content

Capture

Struct Capture 

Source
pub struct Capture { /* private fields */ }
Expand description

Builder for a single report. Construct at a failure site, attach context, then emit.

Implementations§

Source§

impl Capture

Source

pub fn new(kind: EventKind, message: impl Into<String>) -> Self

Begin a capture of kind with a one-line message.

Source

pub fn error_chain<I, S>(self, chain: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Record the outer-to-inner Display chain of an error (e.g. by walking std::error::Error::source).

Source

pub fn domain(self, ctx: &dyn DomainContext) -> Self

Attach project-specific forensic context and adopt its grouping key.

§Panics

Never — including when the DomainContext implementation itself panics. Serializing forensic context is exactly the code most likely to misbehave while a system is already failing: it reaches into the very structures whose corruption is being reported, and an index or unwrap that holds in a healthy process need not hold in this one. Losing the context is a worse report; taking the process down at the detection site is a worse outcome.

A panicking implementation therefore leaves the payload empty and the capture usable, so the report still records that the site fired.

Source

pub fn with_backtrace(self) -> Self

Capture a backtrace at this point.

Source

pub fn backtrace_frames(self, frames: Vec<Frame>) -> Self

Attach pre-built backtrace frames (used by the panic hook).

Source

pub fn preserve( self, artifact_kind: impl Into<String>, src: impl Into<PathBuf>, name: impl Into<String>, note: Option<String>, ) -> Self

Preserve a file or directory alongside the report (copied in on emit) — e.g. a snapshot of a corrupt store for offline fsck.

Source

pub fn emit(self) -> Option<PathBuf>

Build, persist, and return the report directory. Returns None if the recorder was never initialized or the write failed — never panics, so it is safe inside a panic hook.

Reports coalesce by fingerprint: repeated captures of one bug land in the same directory, bumping Report::occurrences and refreshing latest.json, rather than writing a directory per occurrence.

§Panics

Never. That is a guarantee, not an aspiration: this runs at a detection site in a process that is already in trouble, and often from inside the panic hook, where a second panic is an abort that destroys the report.

Making it true takes more than avoiding unwrap in this crate, because the capture path calls adopter code — Redactor::redact on every string, and Redactor::redact_json over the domain payload. A panicking redactor would otherwise take the application down from a logging-shaped call, so the whole capture is unwind-guarded and a panic simply yields None.

Note the direction of that failure: a panic part-way through redaction abandons the report entirely rather than writing what had been redacted so far. A missing report costs a debugging session; a half-redacted one costs the secret.

Nothing can be done about a build using panic = "abort", where no unwind is catchable — there, an adopter’s redactor must not panic.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more