pub struct CliError {
pub kind: ExitKind,
pub code: &'static str,
pub message: String,
pub details: Option<Value>,
}Expand description
Typed CLI error that carries an exit-code kind, a stable
UPPER_SNAKE_CASE code (matching EngineError::code() for
engine-sourced errors), and an optional structured details payload.
Wrap with anyhow::Error via .into() or map_err to propagate up
to main, which renders the error through
output::print_cli_error in the documented {code, message, details}
shape (or memstead: ERROR [<CODE>]: <message> on the text channel).
code is non-optional, so every construction site spells the wire
token — there is no Option-default-to-INTERNAL fallback that
could leak INTERNAL when a callsite forgets to set it.
Engine-sourced errors capture EngineError::code() via
CliError::from_engine_op; setup-layer paths pin their own typed
token at construction time.
details is the structured recovery payload — e.g. HashMismatch
populates {"current": "<hash>"} so scripts can lift the recovery
hash without re-reading the entity. The renderer surfaces it under
the details key of the JSON envelope.
Fields§
§kind: ExitKind§code: &'static str§message: String§details: Option<Value>Implementations§
Source§impl CliError
impl CliError
Sourcepub fn new(
kind: ExitKind,
code: &'static str,
message: impl Into<String>,
) -> Self
pub fn new( kind: ExitKind, code: &'static str, message: impl Into<String>, ) -> Self
Construct a typed CLI error with an exit-kind, wire code, and
human message. Every callsite spells the code at construction
time — there is no Option-default-to-INTERNAL fallback. Use
INTERNAL_CODE explicitly for genuinely-systemic paths.
pub fn with_details(self, details: Value) -> Self
Sourcepub fn with_code(self, code: &'static str) -> Self
pub fn with_code(self, code: &'static str) -> Self
Override the wire code on an existing CliError. This helper exists
for callsites that build an error in steps (e.g.
setup layers that mint the error before knowing whether to
retag it with a more specific code). New code should spell the
final code at CliError::new construction time.
Sourcepub fn effective_code(&self) -> &'static str
pub fn effective_code(&self) -> &'static str
Field accessor preserved as a method for backward compatibility
with the previous Option<&'static str> API. Now a trivial
self.code return; kept so existing call sites don’t need to
flip method-call syntax to field-access syntax.
Sourcepub fn from_engine_op(e: EngineError) -> Self
pub fn from_engine_op(e: EngineError) -> Self
Map an memstead_base::EngineError to a typed CLI error with the
right exit code (NOT_FOUND → 3, HASH_MISMATCH → 4,
validation errors → 5, everything else → 1) and the typed wire
code from EngineError::code(). Recovery payloads
(HashMismatch.current, HasIncomingRefs.referrers,
WikiLinkWithoutRelation.missing, etc.) land under details so
--json callers consume the same {code, message, details}
envelope they get over MCP — bit-identical wire shape across
surfaces is the agent contract this method delivers.
Trait Implementations§
Source§impl Error for CliError
impl Error for CliError
1.30.0 · 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 Freeze for CliError
impl RefUnwindSafe for CliError
impl Send for CliError
impl Sync for CliError
impl Unpin for CliError
impl UnsafeUnpin for CliError
impl UnwindSafe for CliError
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> 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>, which can then be
downcast into Box<dyn 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>, which 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> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> ErrorExt for T
impl<T> ErrorExt for T
impl<T> Fruit for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.