Hmbown/CodeWhale · info · anyhow::Error

Failed to render MCP template JSON: {e}

Error message

Failed to render MCP template JSON: {e}

What it means

mcp_template_json() builds the default MCP config template and serializes it with serde_json::to_string_pretty. The template contains only strings, numbers, and string-keyed maps, so serialization cannot realistically fail; this error is a guard against a future code change that adds a non-serializable shape to the template struct.

Source

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

            connect_timeout: None,
            execute_timeout: None,
            read_timeout: None,
            disabled: true,
            enabled: true,
            required: false,
            enabled_tools: Vec::new(),
            disabled_tools: Vec::new(),
            headers: std::collections::HashMap::new(),
            env_headers: std::collections::HashMap::new(),
            bearer_token_env_var: None,
            scopes: Vec::new(),
            oauth: None,
            oauth_resource: None,
            reviewed_plugin: None,
        },
    );
    serde_json::to_string_pretty(&cfg)
        .map_err(|e| anyhow!("Failed to render MCP template JSON: {e}"))
}

fn init_mcp_config(path: &Path, force: bool) -> Result<WriteStatus> {
    let template = mcp_template_json()?;
    write_template_file(path, &template, force)
}

fn skills_template(name: &str) -> String {
    format!(
        "\
---\n\
name: {name}\n\
description: Quick repo diagnostics and setup guidance\n\
allowed-tools: diagnostics, list_dir, read_file, grep_files, git_status, git_diff\n\
---\n\n\
When this skill is active:\n\
1. Run the diagnostics tool to report workspace and sandbox status.\n\
2. Skim key project files (README.md, Cargo.toml, AGENTS.md) before editing.\n\

View on GitHub (pinned to 8880682c63)

Solutions

  1. As a user: update to a released build — the shipped template is covered by tests
  2. As a developer: run cargo test -p codewhale-tui --lib after editing the template struct
  3. Keep template fields to String, numbers, Vec, and HashMap<String, _>
  4. If you need a custom MCP config, write the JSON file directly instead of using init
Defensive patterns

Strategy: try-catch

Try / catch

let template = mcp_template_json()
    .context("MCP template generation failed; this indicates a broken build, not a config problem")?;
write_template_file(path, &template, force)

Prevention

When it happens

Trigger: Only a code change can trigger it: adding a map with non-string keys, a field type without a Serialize impl, or a value serde_json rejects. Users could hit it via 'codewhale init' on a broken development build.

Common situations: Essentially never in released builds; seen only on dev branches after template struct edits without a matching Serialize derivation or test update.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16). Data as JSON: /api/errors/b2402d2204604dc9. Report an issue: GitHub.