Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 22 variants NotFound, OutputLimitExceeded { stream: OutputStream, limit_bytes: usize, }, 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, }, InvalidRolloutBudget { message: String, }, 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, }, AppServerRpc { method: String, code: i64, message: String, data: Option<Value>, }, AppServerProtocol { message: String, }, CleanupFailed { reason: Box<Error>, cleanup: Box<Error>, }, AppServerLimitExceeded { limit: AppServerLimit, max: usize, }, AppServerConfig { message: String, },
}
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.

§

OutputLimitExceeded

A captured stream passed the ceiling set by CodexBuilder::output_limit.

The run is stopped the same way Error::Cancelled and Error::Timeout stop it, so the child does not keep writing into a buffer nothing will read. No captured bytes are carried here: output seen before the ceiling tripped is logged at warn instead, because returning a prefix as if it were the result is the truncated success this exists to prevent.

The ceiling is off by default and this error cannot occur while it is unset.

Fields

§stream: OutputStream

Which captured stream exceeded the ceiling.

§limit_bytes: usize

The configured ceiling, in bytes, that was exceeded.

§

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.

§

InvalidRolloutBudget

A native rollout-budget configuration was invalid before launch.

Fields

§message: String

The failed invariant.

§

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
§

AppServerRpc

codex app-server answered a request with a JSON-RPC error.

code and message are the server’s own. method is the request that failed, for example turn/steer.

Fields

§method: String

The request method that was rejected.

§code: i64

The JSON-RPC error code.

§message: String

The server’s error message.

§data: Option<Value>

Additional error data, when the server sent any.

§

AppServerProtocol

The connection to codex app-server failed, or the server sent something that is not valid JSON-RPC.

Covers the server exiting or being stopped while a request was waiting, a session that has already ended, and a stream that could not be read or written. When the server wrote to stderr, the last lines are included.

Fields

§message: String

What went wrong.

§

CleanupFailed

A run was being stopped, and stopping or reaping its process failed.

Cancellation, a timeout, an exceeded output limit, a parse error, or an I/O error on the child’s pipes each end a run by terminating the owned process group and waiting on the direct child. When that cleanup succeeds the original error is returned unchanged. When it fails, this is returned instead, so a caller is never told Error::Cancelled or Error::Timeout about a child that may not have been reaped and could still be running.

Match on reason for why the run was stopped. cleanup is the source of this error, so a reporter walking the chain reaches the underlying I/O failure.

Not retried by RetryPolicy, even when reason is a timeout: the previous attempt’s process is not known to be gone.

Fields

§reason: Box<Error>

The error the run would have returned had cleanup succeeded.

§cleanup: Box<Error>

The failure from stopping or waiting on the child.

§

AppServerLimitExceeded

An opt-in codex app-server transport limit was exceeded.

Set with the max_* methods on AppServerBuilder. The connection is ended rather than a message dropped: every waiting request fails with this error, later sends fail at once, and the process the client owns is killed. Distinct from Error::OutputLimitExceeded, which is the lifetime total of CodexBuilder::output_limit.

Fields

§limit: AppServerLimit

Which limit was exceeded.

§max: usize

The configured maximum.

§

AppServerConfig

An AppServerBuilder setting is invalid. Reported by start before anything is spawned.

Fields

§message: String

What is wrong with the configuration.

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 Forget 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> Same for T

Source§

type Output = T

Should always be Self
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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