pub struct Diagnostic(/* private fields */);Expand description
One user-facing error: stable key, rendered message, structured
fields, optional span, hint, and chained source. Construct through
Diagnostic::new from the owning domain module, one constructor
per diagnostic at its owner.
Pointer-sized by design: the payload lives behind one Box so
DiagnosticResult returns stay at the anyhow::Error footprint
on the happy path (the error value is constructed only on the cold
path). A test pins size_of::<Diagnostic>() below.
Implementations§
Source§impl Diagnostic
impl Diagnostic
Sourcepub fn new(
key: &'static str,
message: String,
fields: BTreeMap<String, String>,
) -> Diagnostic
pub fn new( key: &'static str, message: String, fields: BTreeMap<String, String>, ) -> Diagnostic
Generic transport constructor. Domain crates wrap this in one
named constructor per diagnostic. Message, field keys and values,
and hints are sanitized: any INTERNAL_SENTINEL becomes a
space. Never panics on untrusted input.
Sourcepub fn make_fields(pairs: &[(&str, &str)]) -> BTreeMap<String, String>
pub fn make_fields(pairs: &[(&str, &str)]) -> BTreeMap<String, String>
Build a sanitized field map from pairs. Domain constructors use
this so no format! leaks to call sites and no sentinel leaks
to output.
Sourcepub fn key(&self) -> &'static str
pub fn key(&self) -> &'static str
Stable dotted key, e.g. dsl.alias.duplicate_on_field.
Unused for rendering; tests assert on it so a template reword
cannot silently fork one call site.
Sourcepub fn contexts(&self) -> &[String]
pub fn contexts(&self) -> &[String]
Outer call-path frames, outermost first. Empty until
a boundary replays anyhow contexts natively (see
Diagnostic::with_contexts).
Sourcepub fn snapshot(&self) -> Option<&str>
pub fn snapshot(&self) -> Option<&str>
Snapshot section attached at the failure boundary, if any.
Shared handle to the chained source, when one is attached. Lets owners re-chain a cause under a new typed node (such as an exit code) without dropping it.
Sourcepub fn with_span(self, span: Span) -> Diagnostic
pub fn with_span(self, span: Span) -> Diagnostic
Attach a source span (builder style).
Sourcepub fn with_hint(self, hint: String) -> Diagnostic
pub fn with_hint(self, hint: String) -> Diagnostic
Attach a hint (builder style). Sanitized like the message.
Sourcepub fn with_source(self, source: Arc<dyn Error + Sync + Send>) -> Diagnostic
pub fn with_source(self, source: Arc<dyn Error + Sync + Send>) -> Diagnostic
Attach a chained source error (builder style). Preserves error
chains across I/O, filesystem, process, and network boundaries
without anyhow.
Sourcepub fn with_contexts(self, frames: Vec<String>) -> Diagnostic
pub fn with_contexts(self, frames: Vec<String>) -> Diagnostic
Append outer call-path frames (builder style, outermost
first). Sanitized like the message. Unwinding attaches
innermost first, so later (outer) frames prepend ahead of
earlier (inner) ones and the stored order stays outermost
first. Lets DiagnosticResult boundaries carry the step N
call path without anyhow context layers; message() stays
pure.
Sourcepub fn with_snapshot(self, snapshot: &str) -> Diagnostic
pub fn with_snapshot(self, snapshot: &str) -> Diagnostic
Attach the snapshot section (builder style). Sanitized like
the message. Rendered after the failure text, never folded
into message().
Trait Implementations§
Source§impl Clone for Diagnostic
impl Clone for Diagnostic
Source§fn clone(&self) -> Diagnostic
fn clone(&self) -> Diagnostic
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Diagnostic
impl Debug for Diagnostic
Source§impl Display for Diagnostic
impl Display for Diagnostic
impl Eq for Diagnostic
Source§impl Error for Diagnostic
impl Error for Diagnostic
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Auto Trait Implementations§
impl !RefUnwindSafe for Diagnostic
impl !UnwindSafe for Diagnostic
impl Forget for Diagnostic
impl Freeze for Diagnostic
impl Move for Diagnostic
impl Send for Diagnosticwhere
BoxRaw<DiagnosticInner>: Send,
impl Sync for Diagnosticwhere
BoxRaw<DiagnosticInner>: Sync,
impl Unpin for Diagnostic
impl UnsafeUnpin for Diagnostic
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.