Skip to main content

XCheckerError

Enum XCheckerError 

Source
pub enum XCheckerError {
Show 18 variants Config(ConfigError), Phase(PhaseError), Claude(ClaudeError), Runner(RunnerError), Io(Error), SecretDetected { pattern: String, location: String, }, PacketOverflow { used_bytes: usize, used_lines: usize, limit_bytes: usize, limit_lines: usize, }, ConcurrentExecution { id: String, }, PacketPreviewTooLarge { size: usize, }, CanonicalizationFailed { phase: String, reason: String, }, ReceiptWriteFailed { path: String, reason: String, }, ModelResolutionError { alias: String, resolved: String, reason: String, }, Source(SourceError), Fixup(FixupError), SpecId(SpecIdError), Lock(LockError), Llm(LlmError), ValidationFailed { phase: String, issues: Vec<ValidationError>, issue_count: usize, },
}
Expand description

Library-level error type with rich context and user-friendly reporting.

XCheckerError is the primary error type returned by xchecker library operations. It provides:

  • Detailed error information for programmatic handling
  • User-friendly messages with context and suggestions
  • Mapping to CLI exit codes for consistent error reporting

§Error Categories

Errors are organized into categories for better handling:

CategoryDescription
ConfigConfiguration file or CLI argument errors
PhasePhase execution failures
ClaudeClaude CLI integration errors
RunnerProcess execution errors
SecretDetectedSecurity: secrets found in content
PacketOverflowResource: packet size exceeded
LockConcurrency: lock already held

§Exit Code Mapping

Use to_exit_code() to map errors to CLI exit codes:

Exit CodeError Type
2Configuration/CLI argument errors
7Packet overflow
8Secret detected
9Lock held
10Phase timeout
70Claude CLI failure
1Other errors

§User-Friendly Messages

Use display_for_user() to get formatted error messages suitable for end users, including context and actionable suggestions.

§Example

use xchecker_utils::error::XCheckerError;
use xchecker_utils::exit_codes::ExitCode;

fn handle_error(err: XCheckerError) {
    // Get user-friendly message
    eprintln!("{}", err.display_for_user());
     
    // Map to exit code for CLI
    let code = err.to_exit_code();
    std::process::exit(code.as_i32());
}

§Library vs CLI Usage

  • Library consumers: Handle XCheckerError directly, use to_exit_code() if needed
  • CLI: Maps errors to exit codes and displays user-friendly messages

Library code returns XCheckerError and does NOT call std::process::exit().

Variants§

§

Config(ConfigError)

§

Phase(PhaseError)

§

Claude(ClaudeError)

§

Runner(RunnerError)

§

Io(Error)

§

SecretDetected

Fields

§pattern: String
§location: String
§

PacketOverflow

Fields

§used_bytes: usize
§used_lines: usize
§limit_bytes: usize
§limit_lines: usize
§

ConcurrentExecution

Fields

§

PacketPreviewTooLarge

Fields

§size: usize
§

CanonicalizationFailed

Fields

§phase: String
§reason: String
§

ReceiptWriteFailed

Fields

§path: String
§reason: String
§

ModelResolutionError

Fields

§alias: String
§resolved: String
§reason: String
§

Source(SourceError)

§

Fixup(FixupError)

§

SpecId(SpecIdError)

§

Lock(LockError)

§

Llm(LlmError)

§

ValidationFailed

Fields

§phase: String
§issue_count: usize

Implementations§

Source§

impl XCheckerError

Source

pub fn display_for_user(&self) -> String

Get a user-friendly error message with context and actionable suggestions.

This method combines the error message, context, and suggestions into a single formatted string suitable for display to end users. The format is:

Error: <user message>

Context: <context if available>

Suggestions:
  • <suggestion 1>
  • <suggestion 2>
  ...
§Example
use xchecker_utils::error::XCheckerError;

let err = XCheckerError::SecretDetected {
    pattern: "ghp_".to_string(),
    location: "test.txt".to_string(),
};
let message = err.display_for_user();
assert!(message.contains("Security issue"));
assert!(message.contains("Suggestions:"));
Source

pub fn display_for_user_with_redactor( &self, redactor: &SecretRedactor, ) -> String

Get a user-friendly error message with context and actionable suggestions, applying a caller-provided redactor as a final safety net (FR-SEC-19).

Source

pub fn to_exit_code(&self) -> ExitCode

Map this error to the appropriate CLI exit code.

This is the single source of truth for both CLI exit codes and receipt exit_code fields. The mapping follows the documented exit code table:

Exit CodeNameDescription
0SUCCESSCompleted successfully
1INTERNALGeneral failure
2CLI_ARGSInvalid CLI arguments
7PACKET_OVERFLOWPacket size exceeded
8SECRET_DETECTEDSecret found in content
9LOCK_HELDLock already held
10PHASE_TIMEOUTPhase timed out
70CLAUDE_FAILUREClaude CLI failed
§Example
use xchecker_utils::error::XCheckerError;
use xchecker_utils::exit_codes::ExitCode;

let err = XCheckerError::SecretDetected {
    pattern: "ghp_".to_string(),
    location: "test.txt".to_string(),
};
assert_eq!(err.to_exit_code(), ExitCode::SECRET_DETECTED);

Trait Implementations§

Source§

impl Debug for XCheckerError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for XCheckerError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for XCheckerError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<&XCheckerError> for (i32, ErrorKind)

Convert XCheckerError to (exit_code, error_kind) tuple

Source§

fn from(err: &XCheckerError) -> (i32, ErrorKind)

Converts to this type from the input type.
Source§

impl From<ClaudeError> for XCheckerError

Source§

fn from(source: ClaudeError) -> Self

Converts to this type from the input type.
Source§

impl From<ConfigError> for XCheckerError

Source§

fn from(source: ConfigError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for XCheckerError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<FixupError> for XCheckerError

Source§

fn from(source: FixupError) -> Self

Converts to this type from the input type.
Source§

impl From<LlmError> for XCheckerError

Source§

fn from(source: LlmError) -> Self

Converts to this type from the input type.
Source§

impl From<LockError> for XCheckerError

Source§

fn from(source: LockError) -> Self

Converts to this type from the input type.
Source§

impl From<PhaseError> for XCheckerError

Source§

fn from(source: PhaseError) -> Self

Converts to this type from the input type.
Source§

impl From<RunnerError> for XCheckerError

Source§

fn from(source: RunnerError) -> Self

Converts to this type from the input type.
Source§

impl From<SourceError> for XCheckerError

Source§

fn from(source: SourceError) -> Self

Converts to this type from the input type.
Source§

impl From<SpecIdError> for XCheckerError

Source§

fn from(source: SpecIdError) -> Self

Converts to this type from the input type.
Source§

impl UserFriendlyError for XCheckerError

Source§

fn user_message(&self) -> String

Get a user-friendly error message
Source§

fn context(&self) -> Option<String>

Get contextual information about the error
Source§

fn suggestions(&self) -> Vec<String>

Get suggested actions to resolve the error
Source§

fn category(&self) -> ErrorCategory

Get the error category for grouping similar errors

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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