Hmbown/CodeWhale · error

unexpected error

Error message

unexpected error: {detail}

What it means

Companion assertion to the previous test: after expecting Ok and rejecting Warning, the test also panics if doctor_check_mcp_server returns McpServerDoctorStatus::Error for the absolute test-executable path. It means the doctor considered a valid absolute stdio server configuration an outright error.

Solutions

  1. Read the Error detail in the panic message to identify the doctor's failure reason.
  2. Confirm the doctor only errors when the command genuinely cannot run (missing file, non-executable), not merely because the path is unusual.
  3. If the doctor now errors intentionally for this shape, update the test to assert the new variant.

Example fix

// before
McpServerDoctorStatus::Error(detail) => panic!("unexpected error: {detail}"),
// after
McpServerDoctorStatus::Error(detail) => panic!("doctor errored on valid absolute stdio server: {detail}"),
Defensive patterns

Strategy: try-catch

Type guard

fn is_error(s: &McpServerDoctorStatus) -> bool { matches!(s, McpServerDoctorStatus::Error(_)) }

Try / catch

match doctor_check_mcp_server(&server) { McpServerDoctorStatus::Error(d) => panic!("unexpected doctor error: {d}"), _ => {} }

Prevention

When it happens

Trigger: doctor_check_mcp_server returns Error for a config with an absolute command path (current test binary) and args ["serve","--mcp"].

Common situations: Doctor treats an unknown/absolute binary as failed spawn or unsupported transport; environment where current_exe() points somewhere unexpected; doctor validation tightened.

Related errors


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

Appendix: source

Thrown at crates/tui/src/lib.rs:19470

        let mut server = make_server(Some(&executable), &["server/mcp_server.py"], None);
        server.cwd = Some(PathBuf::from("/tmp/codewhale-project"));
        match doctor_check_mcp_server(&server) {
            McpServerDoctorStatus::Ok(detail) => assert!(detail.contains("stdio")),
            other => panic!("Expected Ok when cwd anchors relative path, got {other:?}"),
        }
    }

    #[test]
    fn test_self_hosted_absolute_is_ok() {
        let executable = std::env::current_exe().expect("current test executable");
        let executable = executable.to_string_lossy();
        let server = make_server(Some(&executable), &["serve", "--mcp"], None);
        match doctor_check_mcp_server(&server) {
            McpServerDoctorStatus::Ok(detail) => assert!(detail.contains("stdio server")),
            McpServerDoctorStatus::Warning(detail) => {
                panic!("Absolute path should not warn: {detail}")
            }
            McpServerDoctorStatus::Error(detail) => panic!("unexpected error: {detail}"),
        }
    }

    #[cfg(test)]
    mod mcp_auth_guidance_tests {
        #[test]
        fn mcp_auth_hint_is_actionable_for_connect_failures() {
            let hint = crate::mcp::oauth::auth_required_login_hint("nordic-mcp");
            assert_eq!(
                hint,
                "MCP server 'nordic-mcp' requires OAuth authentication. Run `codewhale mcp login nordic-mcp` to authenticate."
            );
        }
    }

    #[test]
    fn test_empty_command_is_error() {
        let server = make_server(Some(""), &[], None);

View on GitHub (pinned to 433685b202)