{"record":{"id":"12cec1b4f92128ef","repo":"xai-org/grok-build","slug":"path-e","errorCode":null,"errorMessage":"'{path}': {e}","messagePattern":"'\\{path\\}': \\{e\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-pager/src/headless/cli.rs","lineNumber":63,"sourceCode":"                .map(Some)\n                .map_err(|e| anyhow::anyhow!(\"--single: {e}\"))\n        } else if let Some(json_str) = prompt_json {\n            Self::from_json(json_str)\n                .map(Some)\n                .map_err(|e| anyhow::anyhow!(\"--prompt-json: {e}\"))\n        } else if let Some(path) = prompt_file {\n            Self::from_file(path).map(Some)\n        } else {\n            Ok(None)\n        }\n    }\n\n    /// `.json` files are parsed as content blocks, everything else as text.\n    pub fn from_file(path: &Path) -> anyhow::Result<Self> {\n        let content = std::fs::read_to_string(path)\n            .map_err(|e| anyhow::anyhow!(\"Failed to read '{}': {e}\", path.display()))?;\n\n        let context = |e| anyhow::anyhow!(\"'{}': {e}\", path.display());\n        if path.extension().and_then(|e| e.to_str()) == Some(\"json\") {\n            Self::from_json(&content).map_err(context)\n        } else {\n            Self::from_text(&content).map_err(context)\n        }\n    }\n\n    fn from_text(text: &str) -> anyhow::Result<Self> {\n        let trimmed = text.trim();\n        if trimmed.is_empty() {\n            anyhow::bail!(\"prompt is empty\");\n        }\n        Ok(Self::Text(trimmed.to_string()))\n    }\n\n    fn from_json(json_str: &str) -> anyhow::Result<Self> {\n        let blocks = parse_prompt_json(json_str)?;\n        Ok(Self::Blocks(blocks))","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-pager/src/headless/cli.rs#L45-L81","documentation":"After a successful read, from_file parses the content with a context closure |e| anyhow!(\"'{path}': {e}\"): .json files go through from_json (content blocks), everything else through from_text. This error means the file content was read but failed prompt parsing/validation, prefixed with the file path.","triggerScenarios":"from_file given a .json file whose content is not valid prompt content-block JSON, or a non-.json file whose text content fails from_text validation (e.g. empty content).","commonSituations":"A .json prompt file that is actually plain text (wrong extension); an empty prompt file; content-block JSON copied from a different tool/version with an incompatible schema.","solutions":["Read the inner {e} after the path prefix for the parse cause","For JSON content ensure it matches the content-block schema exactly","Rename plain-text files to .txt (or drop .json) so they parse as text","Ensure the file is non-empty and correctly encoded"],"exampleFix":"// before: prompts/req.json containing plain text \"do the thing\"\n// after: rename to prompts/req.txt or convert to content blocks\n[{\"type\": \"text\", \"text\": \"do the thing\"}]","handlingStrategy":"validation","validationCode":"fn validate_prompt_file_content(path: &std::path::Path) -> Result<(), String> {\n    let content = std::fs::read_to_string(path).map_err(|e| e.to_string())?;\n    if content.trim().is_empty() { return Err(\"prompt file is empty\".into()); }\n    if path.extension().and_then(|e| e.to_str()) == Some(\"json\") {\n        serde_json::from_str::<serde_json::Value>(&content)\n            .map(|_| ()).map_err(|e| format!(\"invalid JSON in {}: {e}\", path.display()))?;\n    }\n    Ok(())\n}","typeGuard":"fn prompt_file_parses(path: &std::path::Path) -> bool {\n    std::fs::read_to_string(path).ok()\n        .map(|c| if path.extension().and_then(|e| e.to_str()) == Some(\"json\") {\n            serde_json::from_str::<serde_json::Value>(&c).is_ok() && !c.trim().is_empty()\n        } else { !c.trim().is_empty() })\n        .unwrap_or(false)\n}","tryCatchPattern":"match PromptSource::from_file(&path) {\n    Ok(src) => src,\n    Err(e) if !e.to_string().contains(\"Failed to read\") => {\n        eprintln!(\"prompt content invalid: {e:#}\"); std::process::exit(2);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Match file extension to content (.json only for content-block JSON)","Reject empty prompt files in generation pipelines","Round-trip generated JSON through a parser before writing","Keep prompt files in version control so regressions are caught"],"tags":["prompt","parsing","json","validation"],"backgroundTag":"prompt-parse-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}