1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
//! Error types for `codex-wrapper`.
use std::path::PathBuf;
/// Which of a child's captured streams an [`Error::OutputLimitExceeded`]
/// refers to.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum OutputStream {
/// The child's standard output.
Stdout,
/// The child's standard error.
Stderr,
}
impl std::fmt::Display for OutputStream {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::Stdout => "stdout",
Self::Stderr => "stderr",
})
}
}
/// 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.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
/// The `codex` binary was not found in PATH.
#[error("codex binary not found in PATH")]
NotFound,
/// A captured stream passed the ceiling set by
/// [`CodexBuilder::output_limit`](crate::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.
#[error("codex {stream} exceeded the {limit_bytes}-byte capture limit")]
OutputLimitExceeded {
/// Which captured stream exceeded the ceiling.
stream: OutputStream,
/// The configured ceiling, in bytes, that was exceeded.
limit_bytes: usize,
},
/// 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.
#[error("codex authentication failed: {}", first_line(message))]
Auth {
/// The CLI's stderr, trimmed. Retained whole rather than reduced to
/// the matched line, so nothing is lost to classification.
message: String,
command: String,
exit_code: i32,
working_dir: Option<PathBuf>,
},
/// The CLI rejected the configuration before running.
///
/// An unknown key under `--strict-config`, or a malformed override.
#[error("codex rejected the configuration: {}", first_line(message))]
Config {
/// The CLI's stderr, trimmed.
message: String,
command: String,
exit_code: i32,
working_dir: Option<PathBuf>,
},
/// The working directory is not a trusted directory or git repo, and
/// `--skip-git-repo-check` was not set.
#[error("codex refused an untrusted directory: {}", first_line(message))]
NotTrustedDirectory {
/// The CLI's stderr, trimmed.
message: String,
command: String,
exit_code: i32,
working_dir: Option<PathBuf>,
},
/// The session or thread being resumed does not exist.
#[error("codex session not found: {}", first_line(message))]
SessionNotFound {
/// The CLI's stderr, trimmed.
message: String,
command: String,
exit_code: i32,
working_dir: Option<PathBuf>,
},
/// A codex command failed with a non-zero exit code.
#[error("codex command failed: {command} (exit code {exit_code}){}{}{}", working_dir.as_ref().map(|d| format!(" (in {})", d.display())).unwrap_or_default(), if stdout.is_empty() { String::new() } else { format!("\nstdout: {stdout}") }, if stderr.is_empty() { String::new() } else { format!("\nstderr: {stderr}") })]
CommandFailed {
command: String,
exit_code: i32,
stdout: String,
stderr: String,
working_dir: Option<PathBuf>,
},
/// An I/O error occurred while spawning or communicating with the process.
#[error("io error: {message}{}", working_dir.as_ref().map(|d| format!(" (in {})", d.display())).unwrap_or_default())]
Io {
message: String,
#[source]
source: std::io::Error,
working_dir: Option<PathBuf>,
},
/// The command timed out.
#[error("codex command timed out after {timeout_seconds}s")]
Timeout { timeout_seconds: u64 },
/// 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`].
#[error("token budget exceeded: {total_tokens} of {max_tokens} tokens")]
TokenBudgetExceeded {
/// Tokens recorded when the ceiling was hit. May exceed `max_tokens`,
/// since a turn's usage is only known once it has been spent.
total_tokens: u64,
/// The configured ceiling.
max_tokens: u64,
},
/// A native rollout-budget configuration was invalid before launch.
#[error("invalid Codex rollout budget: {message}")]
InvalidRolloutBudget {
/// The failed invariant.
message: String,
},
/// 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`].
#[cfg(feature = "config")]
#[error("failed to parse {}: {message}", path.display())]
ConfigParse {
/// The file that could not be parsed.
path: PathBuf,
/// The parser's message.
message: String,
},
/// A bypass of codex's safety controls was requested without permission.
///
/// See [`crate::dangerous`]. Never a command failure: nothing ran.
#[error("bypassing codex safety controls requires {variable} to be set")]
DangerousNotAllowed {
/// The environment variable that would have permitted it.
variable: &'static str,
},
/// 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.
#[error("codex run cancelled (after a {grace_seconds}s grace period)")]
Cancelled {
/// How long the group was given to exit before being killed.
grace_seconds: u64,
},
/// JSON parsing failed.
#[cfg(feature = "json")]
#[error("json parse error: {message}")]
Json {
message: String,
#[source]
source: serde_json::Error,
},
/// The installed CLI version does not meet the minimum requirement.
#[error("CLI version {found} does not meet minimum requirement {minimum}")]
VersionMismatch {
found: crate::version::CliVersion,
minimum: crate::version::CliVersion,
},
/// The installed CLI is outside the wrapper's tested-against range.
///
/// Only returned by
/// [`Codex::ensure_tested_cli_version`](crate::Codex::ensure_tested_cli_version).
/// The default path reports drift as a
/// [`CliVersionStatus`](crate::CliVersionStatus) rather than an error.
#[error("CLI version {found} is outside the tested range {tested_min}..={tested_max}")]
UntestedCliVersion {
found: crate::version::CliVersion,
tested_min: crate::version::CliVersion,
tested_max: crate::version::CliVersion,
},
// Add new variants at the end of the enum, below the last one. The enum has no
// `#[repr]`, so inserting a variant earlier shifts the implicit
// discriminant of every variant after it, which `cargo-semver-checks`
// reports as a breaking change (`enum_no_repr_variant_discriminant_changed`)
// and which makes release-plz propose a major version. `Error` carries
// data, so no caller can read those values with `as`; the lint is stricter
// than it needs to be, and it still decides the version.
/// `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`.
#[cfg(feature = "app-server")]
#[error("codex app-server rejected `{method}`: {message} (code {code})")]
AppServerRpc {
/// The request method that was rejected.
method: String,
/// The JSON-RPC error code.
code: i64,
/// The server's error message.
message: String,
/// Additional error data, when the server sent any.
data: Option<serde_json::Value>,
},
/// 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.
#[cfg(feature = "app-server")]
#[error("codex app-server protocol error: {message}")]
AppServerProtocol {
/// What went wrong.
message: String,
},
/// 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`](std::error::Error::source) of this error, so a reporter
/// walking the chain reaches the underlying I/O failure.
///
/// Not retried by [`RetryPolicy`](crate::RetryPolicy), even when `reason`
/// is a timeout: the previous attempt's process is not known to be gone.
#[error("{reason}; cleanup of the codex process then failed, so it may not have been reaped")]
CleanupFailed {
/// The error the run would have returned had cleanup succeeded.
reason: Box<Error>,
/// The failure from stopping or waiting on the child.
#[source]
cleanup: Box<Error>,
},
/// An opt-in `codex app-server` transport limit was exceeded.
///
/// Set with the `max_*` methods on
/// [`AppServerBuilder`](crate::app_server::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`](crate::CodexBuilder::output_limit).
#[cfg(feature = "app-server")]
#[error("codex app-server {limit} limit of {max} exceeded")]
AppServerLimitExceeded {
/// Which limit was exceeded.
limit: crate::app_server::AppServerLimit,
/// The configured maximum.
max: usize,
},
/// An [`AppServerBuilder`](crate::app_server::AppServerBuilder) setting is
/// invalid. Reported by `start` before anything is spawned.
#[cfg(feature = "app-server")]
#[error("invalid codex app-server configuration: {message}")]
AppServerConfig {
/// What is wrong with the configuration.
message: String,
},
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::Io {
message: e.to_string(),
source: e,
working_dir: None,
}
}
}
/// Result type alias for codex-wrapper operations.
pub type Result<T> = std::result::Result<T, Error>;
/// The first non-empty line of a message, for a one-line `Display`.
fn first_line(message: &str) -> &str {
message
.lines()
.map(str::trim)
.find(|line| !line.is_empty())
.unwrap_or(message)
}
/// The class of a failed command, for matching without destructuring.
///
/// Returned by [`Error::failure_kind`].
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum FailureKind {
/// The CLI could not authenticate.
Auth,
/// The CLI rejected the configuration before running.
Config,
/// The working directory was not trusted.
NotTrustedDirectory,
/// The session or thread being resumed does not exist.
SessionNotFound,
/// A non-zero exit that matched no known signature.
Unclassified,
}
/// Signatures observed on `codex-cli` 0.145.0, each from a captured failing
/// run. Matched against stderr, since every one of them exits 1: the exit code
/// carries no information here.
///
/// Deliberately matched on the stable part of each message. The auth line, for
/// instance, also carries a request id and a `cf-ray` header that differ every
/// time.
const SIGNATURES: &[(&str, FailureKind)] = &[
("401 Unauthorized", FailureKind::Auth),
("Missing bearer or basic authentication", FailureKind::Auth),
(
"Not inside a trusted directory",
FailureKind::NotTrustedDirectory,
),
("Error loading config.toml", FailureKind::Config),
("unknown configuration field", FailureKind::Config),
(
"no rollout found for thread id",
FailureKind::SessionNotFound,
),
];
impl Error {
/// The error to return for a run stopped with `reason`, given how cleanup
/// of its process went.
///
/// Every path that stops a child before returning goes through here, so
/// a failed cleanup cannot be reported as the bare stop reason.
pub(crate) fn after_cleanup(reason: Error, cleanup: Result<()>) -> Self {
match cleanup {
Ok(()) => reason,
Err(cleanup) => Error::CleanupFailed {
reason: Box::new(reason),
cleanup: Box::new(cleanup),
},
}
}
/// 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.
#[must_use]
pub fn from_command_failure(
command: String,
exit_code: i32,
stdout: String,
stderr: String,
working_dir: Option<PathBuf>,
) -> Self {
let message = stderr.trim().to_string();
let kind = SIGNATURES
.iter()
.find(|(needle, _)| message.contains(needle))
.map(|(_, kind)| *kind);
match kind {
Some(FailureKind::Auth) => Error::Auth {
message,
command,
exit_code,
working_dir,
},
Some(FailureKind::Config) => Error::Config {
message,
command,
exit_code,
working_dir,
},
Some(FailureKind::NotTrustedDirectory) => Error::NotTrustedDirectory {
message,
command,
exit_code,
working_dir,
},
Some(FailureKind::SessionNotFound) => Error::SessionNotFound {
message,
command,
exit_code,
working_dir,
},
_ => Error::CommandFailed {
command,
exit_code,
stdout,
stderr,
working_dir,
},
}
}
/// The class of this failure, or `None` if it is not a command failure.
#[must_use]
pub fn failure_kind(&self) -> Option<FailureKind> {
match self {
Error::Auth { .. } => Some(FailureKind::Auth),
Error::Config { .. } => Some(FailureKind::Config),
Error::NotTrustedDirectory { .. } => Some(FailureKind::NotTrustedDirectory),
Error::SessionNotFound { .. } => Some(FailureKind::SessionNotFound),
Error::CommandFailed { .. } => Some(FailureKind::Unclassified),
_ => None,
}
}
/// 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.
#[must_use]
pub fn exit_code(&self) -> Option<i32> {
match self {
Error::CommandFailed { exit_code, .. }
| Error::Auth { exit_code, .. }
| Error::Config { exit_code, .. }
| Error::NotTrustedDirectory { exit_code, .. }
| Error::SessionNotFound { exit_code, .. } => Some(*exit_code),
_ => None,
}
}
/// 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.
#[must_use]
pub fn is_deterministic_failure(&self) -> bool {
matches!(
self,
Error::Auth { .. }
| Error::Config { .. }
| Error::NotTrustedDirectory { .. }
| Error::SessionNotFound { .. }
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn display_not_found() {
let err = Error::NotFound;
assert_eq!(err.to_string(), "codex binary not found in PATH");
}
#[test]
fn display_command_failed_minimal() {
let err = Error::CommandFailed {
command: "exec".to_string(),
exit_code: 1,
stdout: String::new(),
stderr: String::new(),
working_dir: None,
};
assert_eq!(err.to_string(), "codex command failed: exec (exit code 1)");
}
#[test]
fn display_command_failed_with_all_fields() {
let err = Error::CommandFailed {
command: "exec".to_string(),
exit_code: 2,
stdout: "out".to_string(),
stderr: "err".to_string(),
working_dir: Some(PathBuf::from("/tmp")),
};
assert_eq!(
err.to_string(),
"codex command failed: exec (exit code 2) (in /tmp)\nstdout: out\nstderr: err"
);
}
#[test]
fn display_io_without_working_dir() {
let source = std::io::Error::other("disk full");
let err = Error::Io {
message: source.to_string(),
source,
working_dir: None,
};
assert_eq!(err.to_string(), "io error: disk full");
}
#[test]
fn display_io_with_working_dir() {
let source = std::io::Error::other("disk full");
let err = Error::Io {
message: source.to_string(),
source,
working_dir: Some(PathBuf::from("/home/user")),
};
assert_eq!(err.to_string(), "io error: disk full (in /home/user)");
}
#[test]
fn display_timeout() {
let err = Error::Timeout {
timeout_seconds: 30,
};
assert_eq!(err.to_string(), "codex command timed out after 30s");
}
#[cfg(feature = "json")]
#[test]
fn display_json() {
let source: serde_json::Error =
serde_json::from_str::<serde_json::Value>("invalid").unwrap_err();
let err = Error::Json {
message: source.to_string(),
source,
};
assert!(err.to_string().starts_with("json parse error:"));
}
#[test]
fn display_version_mismatch() {
let err = Error::VersionMismatch {
found: crate::version::CliVersion::new(0, 100, 0),
minimum: crate::version::CliVersion::new(0, 145, 0),
};
assert_eq!(
err.to_string(),
"CLI version 0.100.0 does not meet minimum requirement 0.145.0"
);
}
// ---------------------------------------------------------------
// Classification (#85)
// ---------------------------------------------------------------
fn classify(stderr: &str) -> Error {
Error::from_command_failure(
"codex exec hi".into(),
1,
String::new(),
stderr.into(),
None,
)
}
/// Each string is transcribed from a captured codex-cli 0.145.0 failure,
/// varying parts and all.
#[test]
fn classifies_every_captured_signature() {
let cases: &[(&str, FailureKind)] = &[
(
"ERROR: unexpected status 401 Unauthorized: Missing bearer or basic authentication in header, url: https://api.openai.com/v1/responses, cf-ray: a272310168bcba62-SJC, request id: req_ef11",
FailureKind::Auth,
),
(
"Not inside a trusted directory and --skip-git-repo-check was not specified.",
FailureKind::NotTrustedDirectory,
),
(
"Error loading config.toml: unknown configuration field `bogus` in -c/--config override",
FailureKind::Config,
),
(
"Error: thread/resume: thread/resume failed: no rollout found for thread id 00000000-0000-0000-0000-000000000000 (code -32600)",
FailureKind::SessionNotFound,
),
];
for (stderr, expected) in cases {
let err = classify(stderr);
assert_eq!(
err.failure_kind(),
Some(*expected),
"misclassified: {stderr}"
);
assert_eq!(err.exit_code(), Some(1));
assert!(err.is_deterministic_failure(), "{stderr}");
}
}
/// An unrecognized failure must keep its output rather than being forced
/// into a class. Classification is allowed to not know.
#[test]
fn an_unknown_failure_stays_command_failed_with_its_output() {
let err = Error::from_command_failure(
"codex exec hi".into(),
2,
"partial stdout".into(),
"something new the CLI started saying".into(),
None,
);
assert_eq!(err.failure_kind(), Some(FailureKind::Unclassified));
assert!(!err.is_deterministic_failure());
match err {
Error::CommandFailed {
stdout,
stderr,
exit_code,
..
} => {
assert_eq!(stdout, "partial stdout");
assert_eq!(stderr, "something new the CLI started saying");
assert_eq!(exit_code, 2);
}
other => panic!("expected CommandFailed, got {other:?}"),
}
}
/// The whole of stderr is kept, not just the matched line, so nothing is
/// lost to classification.
#[test]
fn a_classified_failure_keeps_the_full_message() {
let err = classify(
"ERROR: Reconnecting... 5/5\nERROR: unexpected status 401 Unauthorized: Missing bearer",
);
match &err {
Error::Auth { message, .. } => {
assert!(message.contains("Reconnecting... 5/5"), "{message}");
assert!(message.contains("401 Unauthorized"), "{message}");
}
other => panic!("expected Auth, got {other:?}"),
}
// Display stays one line, leading with the first thing stderr said.
assert_eq!(
err.to_string(),
"codex authentication failed: ERROR: Reconnecting... 5/5"
);
}
#[test]
fn successful_cleanup_returns_the_stop_reason_unchanged() {
let err = Error::after_cleanup(Error::Timeout { timeout_seconds: 7 }, Ok(()));
assert!(
matches!(err, Error::Timeout { timeout_seconds: 7 }),
"{err:?}"
);
}
/// The reason stays matchable and readable, and the cleanup failure is
/// the source, so walking the chain reaches the I/O error beneath it.
#[test]
fn failed_cleanup_carries_the_reason_and_chains_to_the_cleanup_error() {
let cleanup = Error::from(std::io::Error::other("wait failed"));
let err = Error::after_cleanup(Error::Cancelled { grace_seconds: 2 }, Err(cleanup));
assert_eq!(
err.to_string(),
"codex run cancelled (after a 2s grace period); cleanup of the codex process \
then failed, so it may not have been reaped"
);
let Error::CleanupFailed { reason, .. } = &err else {
panic!("expected CleanupFailed, got {err:?}");
};
assert!(
matches!(**reason, Error::Cancelled { grace_seconds: 2 }),
"{reason:?}"
);
let source = std::error::Error::source(&err).expect("cleanup is the source");
assert_eq!(source.to_string(), "io error: wait failed");
let io = source.source().expect("the I/O error is reachable");
assert_eq!(io.to_string(), "wait failed");
// The child did not exit on its own terms, so no exit code is
// reported even if the wrapped reason were to carry one.
assert_eq!(err.failure_kind(), None);
assert_eq!(err.exit_code(), None);
}
#[test]
fn non_command_errors_have_no_failure_kind() {
assert_eq!(Error::NotFound.failure_kind(), None);
assert_eq!(Error::Timeout { timeout_seconds: 5 }.failure_kind(), None);
assert_eq!(Error::NotFound.exit_code(), None);
}
}