{"record":{"id":"84b20469dd71f018","repo":"Hmbown/CodeWhale","slug":"validation-failed-in-auto-mode-content-is-neither-valid-json","errorCode":null,"errorMessage":"Validation failed in auto mode: content is neither valid JSON nor TOML.","messagePattern":"Validation failed in auto mode: content is neither valid JSON nor TOML\\.","errorType":"validation","errorClass":"ToolResult::error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/validate_data.rs","lineNumber":160,"sourceCode":"    if let Some(format_hint) = hint {\n        return match format_hint {\n            DataFormat::Json => validate_json(raw_content, source_name),\n            DataFormat::Toml => validate_toml(raw_content, source_name),\n            DataFormat::Auto => unreachable!(),\n        };\n    }\n\n    let json_result = serde_json::from_str::<serde_json::Value>(raw_content);\n    if let Ok(parsed) = &json_result {\n        return build_success_result(DataFormat::Json, source_name, summarize_json(parsed));\n    }\n\n    let toml_result = toml::from_str::<toml::Value>(raw_content);\n    if let Ok(parsed) = &toml_result {\n        return build_success_result(DataFormat::Toml, source_name, summarize_toml(parsed));\n    }\n\n    let json_error = json_result.err().map(|e| e.to_string()).unwrap_or_default();\n    let toml_error = toml_result.err().map(|e| e.to_string()).unwrap_or_default();\n\n    Ok(\n        ToolResult::error(\n            \"Validation failed in auto mode: content is neither valid JSON nor TOML.\",\n        )\n        .with_metadata(json!({\n            \"valid\": false,\n            \"format\": DataFormat::Auto.as_str(),\n            \"source\": source_name,\n            \"json_error\": json_error,\n            \"toml_error\": toml_error,\n        })),\n    )\n}\n\nfn validate_json(raw_content: &str, source_name: &str) -> Result<ToolResult, ToolError> {\n    match serde_json::from_str::<serde_json::Value>(raw_content) {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/validate_data.rs#L142-L178","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the json_error and toml_error metadata fields for the concrete parse failures.","Fix the content syntax for the format you intended and re-validate.","If the content is another format (YAML, INI), use the correct format/validation tool instead of auto JSON/TOML.","If you know the intended format, pass an explicit format (json or toml) for a single targeted error message.","Remove JSON-incompatible constructs (comments, trailing commas) or TOML-incompatible ones as applicable."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// pre-check content client-side in auto mode\nlet is_json = serde_json::from_str::<serde_json::Value>(content).is_ok();\nlet is_toml = toml::from_str::<toml::Value>(content).is_ok();\nif !is_json && !is_toml {\n    // neither format: fix content or use a format-aware validator\n}","typeGuard":null,"tryCatchPattern":"// caller: inspect per-parser errors in result metadata instead of just the message\nlet result = tool.validate_data(\"auto\", content);\nif !result.metadata[\"valid\"].as_bool().unwrap_or(false) {\n    eprintln!(\"json: {}\", result.metadata[\"json_error\"]);\n    eprintln!(\"toml: {}\", result.metadata[\"toml_error\"]);\n}","preventionTips":["Only use auto mode for content you believe is JSON or TOML; use format-specific tools otherwise.","Strip comments and trailing commas (not valid in strict JSON).","Verify the source file extension matches its actual format.","Check json_error/toml_error metadata rather than guessing."],"tags":["validation","json","toml","auto-detection"],"backgroundTag":"json-parse-error","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}