Hmbown/CodeWhale · error

expected doctor command

Error message

expected doctor command

What it means

Test panic in the offline-doctor CLI tests. The test parses an argv containing the "doctor" subcommand via Cli::try_parse_from and expects cli.command to be Some(Commands::Doctor). The let-else panic fires when parsing succeeded but the selected command is not Doctor — e.g. the argv was consumed by a different subcommand or the Doctor command was renamed/restructured.

Solutions

  1. Print cli.command after parsing to see which variant was selected.
  2. Verify the argv construction still places "doctor" as the subcommand and that --config precedes it correctly.
  3. If the enum variant was renamed, update Commands::Doctor and the destructuring pattern together.

Example fix

// before
let Some(Commands::Doctor(args)) = cli.command.as_ref() else { panic!("expected doctor command"); };
// after
let Some(Commands::Doctor(args)) = cli.command.as_ref() else { panic!("expected doctor command, got {:?}", cli.command); };
Defensive patterns

Strategy: validation

Validate before calling

let cli = Cli::try_parse_from(argv).expect("offline doctor CLI");
assert!(matches!(cli.command, Some(Commands::Doctor(_))), "parsed command is not Doctor: {:?}", cli.command);

Type guard

fn is_doctor(cli: &Cli) -> bool { matches!(cli.command, Some(Commands::Doctor(_))) }

Try / catch

let Some(Commands::Doctor(args)) = cli.command.as_ref() else { panic!("expected doctor command, got {:?}", cli.command) };

Prevention

When it happens

Trigger: Cli::try_parse_from with args ending in "doctor" plus a --config flag yields a Commands variant other than Commands::Doctor(args).

Common situations: Renaming the Doctor command enum variant, changing argument order so a flag swallows "doctor", or the offline flag being parsed as the command.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/eeb7856b632b43e8. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/main/tests.rs:82

    let config_arg = config_path.to_string_lossy().into_owned();

    for suffix in [
        Vec::<&str>::new(),
        vec!["--json"],
        vec!["--context-json"],
        vec!["--check-updates"],
        vec!["--probe-mcp"],
    ] {
        let mut argv = vec![
            "codewhale-tui".to_string(),
            "--config".to_string(),
            config_arg.clone(),
            "doctor".to_string(),
        ];
        argv.extend(suffix.iter().copied().map(str::to_string));
        let cli = Cli::try_parse_from(argv).expect("offline doctor CLI");
        let Some(Commands::Doctor(args)) = cli.command.as_ref() else {
            panic!("expected doctor command");
        };
        let config = load_doctor_config_from_cli(&cli, args).expect("offline doctor config");
        assert!(config.http_headers.is_none());
        assert!(config.sandbox_api_key.is_none());
        assert!(
            config
                .search
                .as_ref()
                .and_then(|search| search.api_key.as_deref())
                .is_none()
        );
        assert_eq!(
            config.base_url.as_deref(),
            Some("https://safe-doctor.example:9443/v1")
        );
        assert_eq!(config.allow_shell, Some(false));
        let rendered = format!("{config:?}");
        for sentinel in [

View on GitHub (pinned to 433685b202)