Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 15 variants NotFound, Auth { message: String, command: String, exit_code: i32, working_dir: Option<PathBuf>, }, Config { message: String, command: String, exit_code: i32, working_dir: Option<PathBuf>, }, NotTrustedDirectory { message: String, command: String, exit_code: i32, working_dir: Option<PathBuf>, }, SessionNotFound { message: String, command: String, exit_code: i32, working_dir: Option<PathBuf>, }, CommandFailed { command: String, exit_code: i32, stdout: String, stderr: String, working_dir: Option<PathBuf>, }, Io { message: String, source: Error, working_dir: Option<PathBuf>, }, Timeout { timeout_seconds: u64, }, TokenBudgetExceeded { total_tokens: u64, max_tokens: u64, }, ConfigParse { path: PathBuf, message: String, }, DangerousNotAllowed { variable: &'static str, }, Cancelled { grace_seconds: u64, }, Json { message: String, source: Error, }, VersionMismatch { found: CliVersion, minimum: CliVersion, }, UntestedCliVersion { found: CliVersion, tested_min: CliVersion, tested_max: CliVersion, },
}
Expand description

Errors returned by codex-wrapper operations.

This enum is #[non_exhaustive]: match arms must include a _ catch-all so new variants can be added without a breaking change. This mirrors claude-wrapper’s Error for cross-crate consistency.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

NotFound

The codex binary was not found in PATH.

§

Auth

The CLI could not authenticate.

Classified from stderr by Error::from_command_failure; see FailureKind for what that costs. Not retried: the CLI has already retried internally by the time this surfaces, and the credentials will not have changed.

Fields

§message: String

The CLI’s stderr, trimmed. Retained whole rather than reduced to the matched line, so nothing is lost to classification.

§command: String
§exit_code: i32
§working_dir: Option<PathBuf>
§

Config

The CLI rejected the configuration before running.

An unknown key under --strict-config, or a malformed override.

Fields

§message: String

The CLI’s stderr, trimmed.

§command: String
§exit_code: i32
§working_dir: Option<PathBuf>
§

NotTrustedDirectory

The working directory is not a trusted directory or git repo, and --skip-git-repo-check was not set.

Fields

§message: String

The CLI’s stderr, trimmed.

§command: String
§exit_code: i32
§working_dir: Option<PathBuf>
§

SessionNotFound

The session or thread being resumed does not exist.

Fields

§message: String

The CLI’s stderr, trimmed.

§command: String
§exit_code: i32
§working_dir: Option<PathBuf>
§

CommandFailed

A codex command failed with a non-zero exit code.

Fields

§command: String
§exit_code: i32
§stdout: String
§stderr: String
§working_dir: Option<PathBuf>
§

Io

An I/O error occurred while spawning or communicating with the process.

Fields

§message: String
§source: Error
§working_dir: Option<PathBuf>
§

Timeout

The command timed out.

Fields

§timeout_seconds: u64
§

TokenBudgetExceeded

A session’s token budget was reached.

Denominated in tokens rather than money because the CLI reports token counts and no cost; see crate::budget.

Fields

§total_tokens: u64

Tokens recorded when the ceiling was hit. May exceed max_tokens, since a turn’s usage is only known once it has been spent.

§max_tokens: u64

The configured ceiling.

§

ConfigParse

A file on disk could not be parsed.

Distinct from Error::Config, which is the CLI rejecting a configuration it was given. This one never ran a command, so it carries no exit code and is not a FailureKind.

Fields

§path: PathBuf

The file that could not be parsed.

§message: String

The parser’s message.

§

DangerousNotAllowed

A bypass of codex’s safety controls was requested without permission.

See crate::dangerous. Never a command failure: nothing ran.

Fields

§variable: &'static str

The environment variable that would have permitted it.

§

Cancelled

The run was cancelled by the caller.

The process group was asked to stop, given grace_seconds, then killed. Distinct from Error::Timeout, which is the client’s own deadline rather than the caller’s decision.

Fields

§grace_seconds: u64

How long the group was given to exit before being killed.

§

Json

JSON parsing failed.

Fields

§message: String
§source: Error
§

VersionMismatch

The installed CLI version does not meet the minimum requirement.

Fields

§minimum: CliVersion
§

UntestedCliVersion

The installed CLI is outside the wrapper’s tested-against range.

Only returned by Codex::ensure_tested_cli_version. The default path reports drift as a CliVersionStatus rather than an error.

Fields

§tested_min: CliVersion
§tested_max: CliVersion

Implementations§

Source§

impl Error

Source

pub fn from_command_failure( command: String, exit_code: i32, stdout: String, stderr: String, working_dir: Option<PathBuf>, ) -> Self

Build an error from a failed command, classifying it by stderr.

Every non-zero exit in this crate goes through here, so a caller can branch on the class rather than substring-matching stderr themselves. An unrecognized failure stays Error::CommandFailed with its output intact, so classification never loses information.

Classification is by message, because it has to be: every failure observed on 0.145.0 exits 1. That makes it sensitive to the CLI rewording a message, which is the cost of doing it here instead of in every caller. tests/contract.rs is where a reworded message should be caught.

Source

pub fn failure_kind(&self) -> Option<FailureKind>

The class of this failure, or None if it is not a command failure.

Source

pub fn exit_code(&self) -> Option<i32>

The process exit code, for any variant that came from one.

Classification moved some failures off Error::CommandFailed, so anything reading an exit code should read it here rather than matching that one variant.

Source

pub fn is_deterministic_failure(&self) -> bool

Whether re-running the identical command could plausibly succeed.

False for the classified failures: each is a deterministic rejection, and the CLI has already retried the auth case internally before it surfaces here.

Trait Implementations§

Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

impl Error for Error

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<Error> for Error

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

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> 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