zed-industries/zed · error

Failed to create Anthropic client

Error message

Failed to create Anthropic client

What it means

Panics inside run_qa when the AnthropicClient constructor fails while setting up the QA client (ANTHROPIC_CLIENT_PLAIN or the batched variant backed by LLM_CACHE_DB). The constructor error — typically inability to open or create the LLM cache database — is swallowed by expect on first QA generation, aborting the whole run instead of surfacing as the anyhow error run_qa already returns for its other steps.

Source

Thrown at crates/edit_prediction_cli/src/qa.rs:194

    run_parse_output(example).context("Failed to execute run_parse_output")?;

    if example.prompt_inputs.is_none() {
        anyhow::bail!("prompt_inputs missing (run context retrieval first)");
    }

    let step_progress = example_progress.start(Step::Qa);

    let model = model_for_backend(args.backend);
    let prompt = build_prompt(example).context("Failed to build QA prompt")?;

    step_progress.set_substatus("generating");

    let response = match args.backend {
        BatchProvider::Anthropic => {
            let client = if args.no_batch {
                ANTHROPIC_CLIENT_PLAIN.get_or_init(|| {
                    AnthropicClient::plain().expect("Failed to create Anthropic client")
                })
            } else {
                ANTHROPIC_CLIENT_BATCH.get_or_init(|| {
                    AnthropicClient::batch(&LLM_CACHE_DB)
                        .expect("Failed to create Anthropic client")
                })
            };

            let messages = vec![anthropic::Message {
                role: anthropic::Role::User,
                content: vec![anthropic::RequestContent::Text {
                    text: prompt,
                    cache_control: None,
                }],
            }];

            let Some(response) = client.generate(model, 1024, messages, None, false).await? else {
                return Ok(());

View on GitHub (pinned to f4178619ac)

Solutions

  1. Make the QA client initialization fallible and return Err from run_qa with the constructor's error attached
  2. Surface the cache DB path so the user can fix or remove it
  3. Initialize required clients once at CLI startup and fail fast with a clear message
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at crates/edit_prediction_cli/src/qa.rs:194 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/3df54cbe46d84a4d. Report an issue: GitHub.