Hmbown/CodeWhale · error · ToolResult::error

Validation failed in auto mode: content is neither valid…

Error message

Validation failed in auto mode: content is neither valid JSON nor TOML.

What it means

The Data validate tool ran in `auto` format mode: it first tried serde_json, then toml, and both parsers rejected the content. The tool returns a summary error while attaching each parser's specific error string as metadata (json_error / toml_error). This is a validation result (ToolResult::error), not an exception.

Solutions

  1. Inspect the json_error and toml_error metadata fields for the concrete parse failures.
  2. Fix the content syntax for the format you intended and re-validate.
  3. If the content is another format (YAML, INI), use the correct format/validation tool instead of auto JSON/TOML.
  4. If you know the intended format, pass an explicit format (json or toml) for a single targeted error message.
  5. Remove JSON-incompatible constructs (comments, trailing commas) or TOML-incompatible ones as applicable.
Defensive patterns

Strategy: validation

Validate before calling

// pre-check content client-side in auto mode
let is_json = serde_json::from_str::<serde_json::Value>(content).is_ok();
let is_toml = toml::from_str::<toml::Value>(content).is_ok();
if !is_json && !is_toml {
    // neither format: fix content or use a format-aware validator
}

Try / catch

// caller: inspect per-parser errors in result metadata instead of just the message
let result = tool.validate_data("auto", content);
if !result.metadata["valid"].as_bool().unwrap_or(false) {
    eprintln!("json: {}", result.metadata["json_error"]);
    eprintln!("toml: {}", result.metadata["toml_error"]);
}

Prevention

When it happens

Trigger: Calling the data validation tool with format=auto (or format omitted and the source path has no .json/.toml extension) on content that neither `serde_json::from_str` nor `toml::from_str` accepts.

Common situations: Validating YAML or INI content with auto mode; a JSON5/relaxed-JSON document (comments, trailing commas); a malformed snippet of either format; pasted output that mixed formats.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/84b20469dd71f018. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/tools/validate_data.rs:160

    if let Some(format_hint) = hint {
        return match format_hint {
            DataFormat::Json => validate_json(raw_content, source_name),
            DataFormat::Toml => validate_toml(raw_content, source_name),
            DataFormat::Auto => unreachable!(),
        };
    }

    let json_result = serde_json::from_str::<serde_json::Value>(raw_content);
    if let Ok(parsed) = &json_result {
        return build_success_result(DataFormat::Json, source_name, summarize_json(parsed));
    }

    let toml_result = toml::from_str::<toml::Value>(raw_content);
    if let Ok(parsed) = &toml_result {
        return build_success_result(DataFormat::Toml, source_name, summarize_toml(parsed));
    }

    let json_error = json_result.err().map(|e| e.to_string()).unwrap_or_default();
    let toml_error = toml_result.err().map(|e| e.to_string()).unwrap_or_default();

    Ok(
        ToolResult::error(
            "Validation failed in auto mode: content is neither valid JSON nor TOML.",
        )
        .with_metadata(json!({
            "valid": false,
            "format": DataFormat::Auto.as_str(),
            "source": source_name,
            "json_error": json_error,
            "toml_error": toml_error,
        })),
    )
}

fn validate_json(raw_content: &str, source_name: &str) -> Result<ToolResult, ToolError> {
    match serde_json::from_str::<serde_json::Value>(raw_content) {

View on GitHub (pinned to 73e0f67d83)