pub struct Error { /* private fields */ }Expand description
The crate’s error type: a pointer-sized handle to a structured
ErrorReason.
Error is a thin wrapper around a boxed ErrorReason — one pointer wide
(size_of::<Error>() equals a pointer) — so a
Result<T, Error> on the crate’s pervasive process-launch path, and any
enum that embeds this one (a caller’s own vcs_core::Error, say), stays
small instead of carrying the largest variant’s captured streams inline. The
shape mirrors std::io::Error / std::io::ErrorKind.
Match on the failure mode through reason:
match err.reason() {
ErrorReason::NotFound { program, .. } => eprintln!("install `{program}`?"),
ErrorReason::Exit { code, .. } => eprintln!("exited with {code}"),
_ => {}
}or reach for the read accessors (code,
program, diagnostic, the is_*
predicates, …), which delegate to the inner ErrorReason.
Display, Debug, and
source delegate too, so the manual Debug
(200-byte stream previews, PATH redaction, control-/bidi-sanitizing) and
the thiserror Display behave exactly as when matching the reason
directly — the wrapper adds no envelope of its own.
Implementations§
Source§impl Error
impl Error
Sourcepub fn reason(&self) -> &ErrorReason
pub fn reason(&self) -> &ErrorReason
The structured ErrorReason behind this error — the enum to match
on for the failure mode. Error is a pointer-sized wrapper; this
borrows the boxed reason without moving it.
Sourcepub fn into_reason(self) -> ErrorReason
pub fn into_reason(self) -> ErrorReason
Consume the wrapper and hand back the owned ErrorReason — for when
you need to move a field out of the reason (a captured stream, the owned
io::Error) rather than borrow it via reason, or to
match err.into_reason() { … } and bind fields by value.
Sourcepub fn kind(&self) -> ErrorKind
pub fn kind(&self) -> ErrorKind
This failure’s ErrorKind — its total classification into one coarse
routing bucket. See ErrorReason::kind for the full mapping. A routing
answer, not a replacement for reason when you need the
details.
Sourcepub fn diagnostic(&self) -> Option<&str>
pub fn diagnostic(&self) -> Option<&str>
The best human-facing message for a failed run — see
ErrorReason::diagnostic.
Sourcepub fn stdout(&self) -> Option<&str>
pub fn stdout(&self) -> Option<&str>
The captured standard output for the stream-bearing variants — see
ErrorReason::stdout.
Sourcepub fn stderr(&self) -> Option<&str>
pub fn stderr(&self) -> Option<&str>
The captured standard error for the stream-bearing variants — see
ErrorReason::stderr.
Sourcepub fn stdout_bytes(&self) -> Option<&[u8]>
pub fn stdout_bytes(&self) -> Option<&[u8]>
The exact captured stdout bytes, when available — see
ErrorReason::stdout_bytes.
Sourcepub fn combined(&self) -> Option<String>
pub fn combined(&self) -> Option<String>
Standard output followed by standard error, joined — see
ErrorReason::combined.
Sourcepub fn program(&self) -> Option<&str>
pub fn program(&self) -> Option<&str>
The program this error is attributed to — see ErrorReason::program.
Sourcepub fn is_not_found(&self) -> bool
pub fn is_not_found(&self) -> bool
Whether the program could not be located — see
ErrorReason::is_not_found.
Sourcepub fn is_permission_denied(&self) -> bool
pub fn is_permission_denied(&self) -> bool
Whether this is a spawn/IO permission denial — see
ErrorReason::is_permission_denied.
Sourcepub fn is_transient(&self) -> bool
pub fn is_transient(&self) -> bool
Whether this is a transient spawn/IO condition a bare retry can clear —
see ErrorReason::is_transient.
Sourcepub fn code(&self) -> Option<i32>
pub fn code(&self) -> Option<i32>
The process exit code for a non-zero Exit — see
ErrorReason::code.
Sourcepub fn signal(&self) -> Option<i32>
pub fn signal(&self) -> Option<i32>
The signal number for a signal-terminated run — see
ErrorReason::signal.
Sourcepub fn timeout_duration(&self) -> Option<Duration>
pub fn timeout_duration(&self) -> Option<Duration>
The run deadline that elapsed for a timeout — see
ErrorReason::timeout_duration.
Sourcepub fn output_overflow(&self) -> Option<OutputOverflow>
pub fn output_overflow(&self) -> Option<OutputOverflow>
The overflow counters of an output-too-large failure — see
ErrorReason::output_overflow.
Sourcepub fn unsupported_operation(&self) -> Option<&str>
pub fn unsupported_operation(&self) -> Option<&str>
The operation description of an unsupported-operation failure — see
ErrorReason::unsupported_operation.
Sourcepub fn is_timeout(&self) -> bool
pub fn is_timeout(&self) -> bool
Whether the run was killed for exceeding its timeout — see
ErrorReason::is_timeout.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Whether the run was deliberately cancelled — see
ErrorReason::is_cancelled.
Sourcepub fn is_signalled(&self) -> bool
pub fn is_signalled(&self) -> bool
Whether the run was killed by a signal — see
ErrorReason::is_signalled.
Source§impl Error
impl Error
Sourcepub fn parse(program: impl Into<String>, message: impl Into<String>) -> Error
pub fn parse(program: impl Into<String>, message: impl Into<String>) -> Error
Construct a Parse from a caller-supplied parser’s own
failure message. Unlike exit/timeout/signalled/spawn/not_found/
stdin above (#[doc(hidden)] insulated constructors meant for test
doubles), this one is left on the documented public surface: an
external parser that inspects a tool’s output outside this crate’s own
try_parse helpers has no other way to report a parse failure as an
ErrorReason::Parse once the variant is #[non_exhaustive], and that path is
a normal production use, not just a test-doubling convenience.
Trait Implementations§
Source§impl Debug for Error
Debug delegates to the inner ErrorReason’s manual Debug, so {e:?}
and .unwrap() panic messages keep the same bounded stream previews and
PATH redaction — the wrapper prints exactly the reason, no envelope.
impl Debug for Error
Debug delegates to the inner ErrorReason’s manual Debug, so {e:?}
and .unwrap() panic messages keep the same bounded stream previews and
PATH redaction — the wrapper prints exactly the reason, no envelope.
Source§impl Error for Error
impl Error for Error
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()