aix-rs 1.0.0

Manage AI gateway profiles and launch AI coding tools with the right credentials
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
#[derive(Debug, thiserror::Error)]
pub enum AixError {
    #[allow(dead_code)]
    #[error("not yet implemented: {0}")]
    NotImplemented(&'static str),

    #[error("unknown config format: {ext}")]
    UnknownFormat { ext: String },

    #[error("failed to parse {path}: {source}")]
    ParseError {
        path: std::path::PathBuf,
        #[source]
        source: Box<dyn std::error::Error + Send + Sync>,
    },

    #[error("default_profile \"{0}\" is not defined in profiles")]
    UnknownDefaultProfile(String),

    #[error("API-key profiles require endpoint.base_url or a profile base_url")]
    MissingEndpointUrl,

    #[error("ChatGPT profile {name:?} must not configure base_url because its authorization is restricted to OpenAI's public API")]
    ChatGptProfileBaseUrl { name: String },

    #[error("this command requires an API-key profile; ChatGPT authentication is not supported by this command")]
    ChatGptAuthUnsupported,

    #[error("tool {tool:?} is not configured to consume ChatGPT-plan credentials; configure [tools.{tool}.chatgpt] with access_token_env")]
    ChatGptToolNotConfigured { tool: String },

    #[error("ChatGPT local_gateway transport is supported only for OpenAI-compatible OpenCode or Codex app-server bindings; configure an eligible tool or use transport = \"direct\" (tool {tool:?})")]
    ChatGptLocalGatewayUnsupported { tool: String },

    #[error(
        "`aix auth login` requires interactive browser authorization; remove --non-interactive"
    )]
    AuthLoginRequiresInteractive,

    #[error("aix auth login/logout only apply to profiles configured with auth.type = chatgpt")]
    AuthProfileNotChatGpt,

    #[error("local auth storage failed: {0}")]
    AuthStoreIo(#[source] std::io::Error),

    #[error("local auth storage contains an invalid or unsupported record")]
    AuthStoreMalformed,

    #[error(
        "ChatGPT authorization could not be completed; check the browser sign-in and try again"
    )]
    AuthAuthorizationDenied,

    #[error("ChatGPT authorization callback could not be verified")]
    AuthCallbackInvalid,

    #[error("timed out waiting for the ChatGPT browser callback")]
    AuthCallbackTimeout,

    #[error("ChatGPT rejected the OAuth request (HTTP {status})")]
    AuthOAuthRejected { status: u16, terminal: bool },

    #[error("ChatGPT authentication failed; sign in again")]
    AuthIdentityInvalid,

    #[error("ChatGPT authorization completed for a different account; saved credentials were not changed")]
    AuthIdentityMismatch,

    #[error("ChatGPT plan usage is not enabled for this profile")]
    AuthPlanUsageDisabled,

    #[error("this ChatGPT profile has no usable refresh token; run `aix auth login` again")]
    AuthRefreshTokenUnavailable,

    #[error("ChatGPT token refresh is not yet allowed; retry after the saved refresh time")]
    AuthRefreshNotYetAllowed,

    #[error("ChatGPT {operation} request failed or timed out")]
    AuthNetwork { operation: &'static str },

    #[error("ChatGPT returned an incomplete or invalid OAuth response")]
    AuthProtocol,

    #[error("no model specified and no default model is configured; pass --model <MODEL> or configure [models].default or [profiles.<PROFILE>.models].default")]
    NoModelConfigured,

    #[error("`aix ask` needs an instruction: provide PROMPT; files alone are context, not an instruction")]
    AskInstructionRequired,

    #[error("`aix ask` needs a prompt or non-empty piped stdin; see `aix ask --help`")]
    AskInputRequired,

    #[error("prompt names must not be empty")]
    EmptyPromptName,

    #[error("`aix prompt` needs a preset NAME or `--list`")]
    PromptNameRequired,

    #[error("prompt preset {name:?} must have a non-empty {field}")]
    EmptyPromptField { name: String, field: &'static str },

    #[error("prompt preset {name:?} is not defined\n\nAvailable prompts:\n{available_hint}")]
    PromptNotFound {
        name: String,
        available_hint: String,
    },

    #[error("failed to read stdin: {source}")]
    AskStdinRead {
        #[source]
        source: std::io::Error,
    },

    #[error("failed to read explicit input file {path}: {source}")]
    AskFileRead {
        path: std::path::PathBuf,
        #[source]
        source: std::io::Error,
    },

    #[error("model default in {scope} must be a non-empty model ID")]
    EmptyModelDefault { scope: String },

    #[error("profiles.{profile}.tool_configs.pi.agent_dir must not be empty")]
    EmptyPiAgentDir { profile: String },

    #[error("Pi agent configuration selection conflicts with explicit {option}; remove it so the selected profile can control the Pi agent directory and connection")]
    PiAgentConfigArgumentConflict { option: &'static str },

    #[error("profile-specific Pi agent configuration requires API-key profile authentication; ChatGPT authentication is not supported")]
    PiAgentConfigChatGptUnsupported,

    #[error("model alias name in {scope} must not be empty")]
    EmptyModelAliasName { scope: String },

    #[error("model alias target for {alias:?} in {scope} must not be empty")]
    EmptyModelAliasTarget { scope: String, alias: String },

    #[allow(dead_code)]
    #[error("ambiguous secret source for {field}: specify exactly one of env / file / command")]
    AmbiguousSecretSource { field: String },

    #[error("no config file found")]
    NoConfigFile,

    #[allow(dead_code)]
    #[error("env var {name:?} is not set")]
    SecretMissingEnvVar { name: String },

    #[allow(dead_code)]
    #[error("failed to read secret file {path}: {source}")]
    SecretFileRead {
        path: std::path::PathBuf,
        #[source]
        source: std::io::Error,
    },

    #[allow(dead_code)]
    #[error("secret command {cmd:?} failed (exit code: {exit_code:?})")]
    SecretCommandFailed { cmd: String, exit_code: Option<i32> },

    #[allow(dead_code)]
    #[error("failed to spawn secret command {cmd:?}: {source}")]
    SecretCommandSpawn {
        cmd: String,
        #[source]
        source: std::io::Error,
    },

    #[allow(dead_code)]
    #[error("secret command {cmd:?} produced non-UTF-8 output")]
    SecretCommandEncoding { cmd: String },

    #[allow(dead_code)]
    #[error("failed to load env file {path}: {source}")]
    EnvFileLoad {
        path: std::path::PathBuf,
        #[source]
        source: Box<dyn std::error::Error + Send + Sync>,
    },

    #[error("profile \"{name}\" is not defined\n\nAvailable profiles:\n{available_hint}")]
    ProfileNotFound {
        name: String,
        available_hint: String,
    },

    #[allow(dead_code)]
    #[error("no profile specified and no default_profile set in config")]
    NoProfile,

    #[allow(dead_code)]
    #[error(
        "duplicate profile label \"{label}\" — found in profiles \"{first}\" and \"{second}\""
    )]
    DuplicateLabel {
        label: String,
        first: String,
        second: String,
    },

    #[error("config must define at least one profile in [profiles]")]
    NoProfilesConfigured,

    #[error("invalid environment variable name {name:?} in profile {profile:?}")]
    InvalidEnvironmentVariableName { profile: String, name: String },

    #[error("tool names must not be empty")]
    EmptyToolName,

    #[error("configured command for tool {name:?} must not be empty")]
    EmptyToolCommand { name: String },

    #[error(
        "{argument} conflicts with the selected Codex configuration directory and aix-managed connection"
    )]
    CodexConfigArgumentConflict { argument: &'static str },

    #[error("ChatGPT access-token environment variable CODEX_HOME conflicts with the selected Codex configuration directory")]
    CodexConfigEnvironmentConflict,

    #[error("profile {profile:?} has an empty path for tool_configs.{tool}")]
    EmptyToolConfigPath { profile: String, tool: &'static str },

    #[error("OpenCode arguments must not select another config source or external server while profile-specific configuration is active")]
    OpenCodeConfigArgumentConflict,

    #[error("failed to stage profile-specific OpenCode configuration: {source}")]
    OpenCodeConfigStage {
        #[source]
        source: std::io::Error,
    },

    #[error("run policy names must not be empty")]
    EmptyRunPolicyName,

    #[error("run policy {name:?} must set a valid positive max_duration such as 30m or 2h")]
    InvalidRunPolicyDuration { name: String },

    #[error("run policy {name:?} allowed_models must be a non-empty list when configured")]
    EmptyRunPolicyModels { name: String },

    #[error("run policy {name:?} allowed_models must not contain empty strings")]
    EmptyRunPolicyModel { name: String },

    #[error("run policy {name:?} tags must not contain empty strings")]
    EmptyRunPolicyTag { name: String },

    #[error("run policy {name:?} references undefined profile {profile:?}")]
    UnknownRunPolicyProfile { name: String, profile: String },

    #[error("run policy {name:?} is not defined\n\nAvailable run policies:\n{available_hint}")]
    RunPolicyNotFound {
        name: String,
        available_hint: String,
    },

    #[error("run policy has a fixed profile that conflicts with the global --profile")]
    RunPolicyProfileConflict,

    #[error("--duration {duration:?} exceeds run policy {policy:?} maximum {max_duration:?}")]
    RunPolicyDurationExceeded {
        policy: String,
        duration: String,
        max_duration: String,
    },

    #[error("a requested model is not allowed by the selected run policy")]
    RunPolicyModelNotAllowed,

    #[error("run policy {policy:?} requests {constraint} enforcement, but this transport has no authoritative enforcement mechanism")]
    RunPolicyEnforcementUnavailable {
        policy: String,
        constraint: &'static str,
    },

    #[error("run policy {policy:?} reached its effective duration of {duration:?}; child process was terminated")]
    RunPolicyDurationReached { policy: String, duration: String },

    #[error("invalid environment variable name {name:?} in tool {tool:?}")]
    InvalidToolEnvironmentVariableName { tool: String, name: String },

    #[error("ChatGPT access-token environment variable {name:?} for tool {tool:?} must not also appear in clear_env")]
    ChatGptAccessTokenEnvCleared { tool: String, name: String },

    #[allow(dead_code)]
    #[error("profile selection cancelled")]
    SelectionCancelled,

    #[allow(dead_code)]
    #[error("no profile selected; pass PROFILE or --profile, set AIX_PROFILE, or configure default_profile (interactive selection requires a TTY and is disabled by --non-interactive)")]
    NoInteractiveTerminal,

    #[error("exec requires a command after --")]
    ExecNoCommand,

    #[error("run requires a command after --")]
    RunNoCommand,

    #[error("`aix {command}` has been removed; manage API keys in your provider's portal")]
    RemovedCommand { command: &'static str },

    #[error("invalid run duration; use a positive finite duration such as 30m or 2h")]
    InvalidRunDuration,

    #[error("allowed model names must not be empty")]
    EmptyRunModel,

    #[error("run history I/O failed at {path}: {source}")]
    RunHistoryIo {
        path: std::path::PathBuf,
        #[source]
        source: std::io::Error,
    },

    #[error("run record {run_id} was not found")]
    RunNotFound { run_id: String },

    #[error("failed to encode run record: {0}")]
    RunRecordSerialization(#[from] serde_json::Error),

    #[error("failed to install interrupt handler: {0}")]
    RunInterruptHandler(#[source] std::io::Error),

    #[error(
        "`aix shell` does not accept commands after --; use `aix exec` to run a command directly"
    )]
    ShellExtraArgs,

    #[error(
        "JSON output is only supported by `aix current`, `aix profiles`, `aix policies`, `aix policy show`, `aix spend`, `aix models`, `aix status`, `aix doctor`, `aix gate`, `aix usage`, `aix ask`, `aix prompt`, `aix auth status`, and `aix runs`"
    )]
    JsonUnsupportedCommand,

    #[error("invalid usage date range: {reason}")]
    InvalidUsageRange { reason: String },

    #[error("executable not found: {program}")]
    ExecutableNotFound { program: String },

    #[error("failed to spawn {program}: {source}")]
    ProcessSpawn {
        program: String,
        #[source]
        source: std::io::Error,
    },

    #[error("failed while waiting for {program}: {source}")]
    ProcessWait {
        program: String,
        #[source]
        source: std::io::Error,
    },

    #[error("gateway returned HTTP {status}: {body}")]
    GatewayError { status: u16, body: String },

    #[error("gateway protocol error: {0}")]
    GatewayProtocolError(&'static str),

    #[error("gateway request failed with HTTP {status}")]
    GatewayRequestFailed { status: u16 },

    #[error("HTTP request failed: {0}")]
    HttpError(#[from] reqwest::Error),

    #[error("doctor found one or more failed checks")]
    DoctorChecksFailed { category: DoctorFailureCategory },

    #[error("gate found one or more failed checks")]
    GateChecksFailed { category: GateFailureCategory },
}

#[derive(Debug, Clone, Copy)]
pub(crate) enum DoctorFailureCategory {
    Internal,
    Config,
    Secret,
    Authentication,
    Network,
    Budget,
}

#[derive(Debug, Clone, Copy)]
pub(crate) enum GateFailureCategory {
    Config,
    Secret,
    Authentication,
    Network,
    Budget,
}

impl GateFailureCategory {
    fn exit_code(self) -> i32 {
        match self {
            Self::Config => 2,
            Self::Secret => 3,
            Self::Authentication => 4,
            Self::Network => 5,
            Self::Budget => 6,
        }
    }
}

impl DoctorFailureCategory {
    fn exit_code(self) -> i32 {
        match self {
            Self::Internal => 1,
            Self::Config => 2,
            Self::Secret => 3,
            Self::Authentication => 4,
            Self::Network => 5,
            Self::Budget => 6,
        }
    }
}

impl AixError {
    pub fn exit_code(&self) -> i32 {
        match self {
            Self::UnknownFormat { .. }
            | Self::ParseError { .. }
            | Self::UnknownDefaultProfile(_)
            | Self::MissingEndpointUrl
            | Self::ChatGptProfileBaseUrl { .. }
            | Self::ChatGptAuthUnsupported
            | Self::ChatGptToolNotConfigured { .. }
            | Self::ChatGptLocalGatewayUnsupported { .. }
            | Self::AuthLoginRequiresInteractive
            | Self::AuthProfileNotChatGpt
            | Self::NoModelConfigured
            | Self::AskInstructionRequired
            | Self::AskInputRequired
            | Self::EmptyPromptName
            | Self::PromptNameRequired
            | Self::EmptyPromptField { .. }
            | Self::PromptNotFound { .. }
            | Self::AskStdinRead { .. }
            | Self::AskFileRead { .. }
            | Self::EmptyModelDefault { .. }
            | Self::EmptyPiAgentDir { .. }
            | Self::PiAgentConfigArgumentConflict { .. }
            | Self::PiAgentConfigChatGptUnsupported
            | Self::EmptyModelAliasName { .. }
            | Self::EmptyModelAliasTarget { .. }
            | Self::AmbiguousSecretSource { .. }
            | Self::NoConfigFile
            | Self::ProfileNotFound { .. }
            | Self::NoProfile
            | Self::DuplicateLabel { .. }
            | Self::NoProfilesConfigured
            | Self::InvalidEnvironmentVariableName { .. }
            | Self::EmptyToolName
            | Self::EmptyToolCommand { .. }
            | Self::CodexConfigArgumentConflict { .. }
            | Self::CodexConfigEnvironmentConflict
            | Self::EmptyToolConfigPath { .. }
            | Self::OpenCodeConfigArgumentConflict
            | Self::EmptyRunPolicyName
            | Self::InvalidRunPolicyDuration { .. }
            | Self::EmptyRunPolicyModels { .. }
            | Self::EmptyRunPolicyModel { .. }
            | Self::EmptyRunPolicyTag { .. }
            | Self::UnknownRunPolicyProfile { .. }
            | Self::RunPolicyNotFound { .. }
            | Self::RunPolicyProfileConflict
            | Self::RunPolicyDurationExceeded { .. }
            | Self::RunPolicyModelNotAllowed
            | Self::RunPolicyEnforcementUnavailable { .. }
            | Self::InvalidToolEnvironmentVariableName { .. }
            | Self::ChatGptAccessTokenEnvCleared { .. }
            | Self::SelectionCancelled
            | Self::NoInteractiveTerminal
            | Self::ExecNoCommand
            | Self::RunNoCommand
            | Self::RemovedCommand { .. }
            | Self::InvalidRunDuration
            | Self::EmptyRunModel
            | Self::RunNotFound { .. }
            | Self::ShellExtraArgs
            | Self::JsonUnsupportedCommand
            | Self::InvalidUsageRange { .. }
            | Self::ExecutableNotFound { .. } => 2,
            Self::SecretMissingEnvVar { .. }
            | Self::SecretFileRead { .. }
            | Self::SecretCommandFailed { .. }
            | Self::SecretCommandSpawn { .. }
            | Self::SecretCommandEncoding { .. }
            | Self::EnvFileLoad { .. }
            | Self::AuthStoreIo(_)
            | Self::AuthStoreMalformed => 3,
            Self::OpenCodeConfigStage { .. } => 3,
            Self::GatewayError {
                status: 401 | 403, ..
            }
            | Self::GatewayRequestFailed { status: 401 | 403 }
            | Self::AuthAuthorizationDenied
            | Self::AuthCallbackInvalid
            | Self::AuthOAuthRejected { .. }
            | Self::AuthIdentityInvalid
            | Self::AuthIdentityMismatch
            | Self::AuthPlanUsageDisabled
            | Self::AuthRefreshTokenUnavailable
            | Self::AuthRefreshNotYetAllowed => 4,
            Self::GatewayError { status: 402, .. } | Self::GatewayRequestFailed { status: 402 } => {
                6
            }
            Self::GatewayError { .. }
            | Self::GatewayRequestFailed { .. }
            | Self::GatewayProtocolError(_)
            | Self::HttpError(_)
            | Self::AuthCallbackTimeout
            | Self::AuthNetwork { .. }
            | Self::AuthProtocol => 5,
            Self::RunPolicyDurationReached { .. } => 124,
            Self::DoctorChecksFailed { category } => category.exit_code(),
            Self::GateChecksFailed { category } => category.exit_code(),
            Self::NotImplemented(_)
            | Self::ProcessSpawn { .. }
            | Self::ProcessWait { .. }
            | Self::RunHistoryIo { .. }
            | Self::RunRecordSerialization(_)
            | Self::RunInterruptHandler(_) => 1,
        }
    }
}

pub fn exit_code(error: &color_eyre::Report) -> i32 {
    error
        .downcast_ref::<AixError>()
        .map_or(1, AixError::exit_code)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn profile_not_found_message_includes_name_and_available() {
        let e = AixError::ProfileNotFound {
            name: "swtb".to_string(),
            available_hint: "  work\n  private".to_string(),
        };
        let msg = e.to_string();
        assert!(msg.contains("swtb"), "must mention the missing name: {msg}");
        assert!(msg.contains("work"), "must list available profiles: {msg}");
        assert!(
            msg.contains("Available profiles"),
            "must have header: {msg}"
        );
    }

    #[test]
    fn no_profile_message_is_clear() {
        let e = AixError::NoProfile;
        let msg = e.to_string();
        assert!(msg.contains("profile") || msg.contains("default"));
    }

    #[test]
    fn duplicate_label_message_includes_label_and_profiles() {
        let e = AixError::DuplicateLabel {
            label: "Work".to_string(),
            first: "alpha".to_string(),
            second: "beta".to_string(),
        };
        let msg = e.to_string();
        assert!(msg.contains("Work"), "got: {msg}");
        assert!(msg.contains("alpha"), "got: {msg}");
        assert!(msg.contains("beta"), "got: {msg}");
    }

    #[test]
    fn selection_cancelled_message_is_clear() {
        let e = AixError::SelectionCancelled;
        let msg = e.to_string();
        assert!(
            msg.contains("cancel") || msg.contains("select"),
            "got: {msg}"
        );
    }

    #[test]
    fn no_interactive_terminal_message_contains_profile() {
        let e = AixError::NoInteractiveTerminal;
        let msg = e.to_string();
        assert!(msg.contains("profile"), "got: {msg}");
    }

    #[test]
    fn executable_not_found_message_includes_program_name() {
        let e = AixError::ExecutableNotFound {
            program: "pi".to_string(),
        };
        assert!(e.to_string().contains("pi"), "got: {}", e);
    }

    #[test]
    fn gateway_error_message_includes_status_and_body() {
        let e = AixError::GatewayError {
            status: 403,
            body: "Forbidden".to_string(),
        };
        let msg = e.to_string();
        assert!(msg.contains("403"), "got: {msg}");
        assert!(msg.contains("Forbidden"), "got: {msg}");
    }

    #[test]
    fn process_spawn_message_includes_program_name() {
        let e = AixError::ProcessSpawn {
            program: "claude".to_string(),
            source: std::io::Error::new(std::io::ErrorKind::NotFound, "no such file"),
        };
        assert!(e.to_string().contains("claude"), "got: {}", e);
    }

    #[test]
    fn exit_codes_use_the_documented_process_categories() {
        assert_eq!(AixError::NoConfigFile.exit_code(), 2);
        assert_eq!(AixError::ShellExtraArgs.exit_code(), 2);
        assert_eq!(
            AixError::ExecutableNotFound {
                program: "missing-tool".to_string()
            }
            .exit_code(),
            2
        );
        assert_eq!(
            AixError::SecretMissingEnvVar {
                name: "AIX_KEY".to_string()
            }
            .exit_code(),
            3
        );
        assert_eq!(
            AixError::GatewayError {
                status: 403,
                body: "forbidden".to_string()
            }
            .exit_code(),
            4
        );
        assert_eq!(
            AixError::GatewayError {
                status: 502,
                body: "unavailable".to_string()
            }
            .exit_code(),
            5
        );
        assert_eq!(
            AixError::GatewayError {
                status: 402,
                body: "budget exhausted".to_string()
            }
            .exit_code(),
            6
        );
        assert_eq!(
            AixError::GatewayRequestFailed { status: 402 }.exit_code(),
            6
        );
        assert_eq!(
            AixError::GatewayRequestFailed { status: 401 }.exit_code(),
            4
        );
        assert_eq!(
            AixError::GatewayRequestFailed { status: 403 }.exit_code(),
            4
        );
        assert_eq!(
            AixError::GatewayRequestFailed { status: 429 }.exit_code(),
            5
        );
        assert_eq!(AixError::NotImplemented("example").exit_code(), 1);
    }
}