{"record":{"id":"596b0315be31a552","repo":"Hmbown/CodeWhale","slug":"unexpected-patch-directive-raw-line","errorCode":null,"errorMessage":"unexpected patch directive: {raw_line}","messagePattern":"unexpected patch directive: (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/eval.rs","lineNumber":704,"sourceCode":"    let file_rel = header\n        .strip_prefix(\"*** Update File: \")\n        .ok_or_else(|| anyhow!(\"only *** Update File patches are supported\"))?;\n    if file_rel.contains(\"..\") {\n        return Err(anyhow!(\"patch path must be workspace-relative\"));\n    }\n\n    let file_path = root.join(file_rel);\n    let original = read_workspace_file(&file_path)?;\n    let had_trailing_newline = original.ends_with('\\n');\n    let mut file_lines: Vec<String> = original.lines().map(|l| l.to_string()).collect();\n\n    let mut cursor = 0usize;\n    for raw_line in lines {\n        if raw_line == \"*** End Patch\" {\n            break;\n        }\n        if raw_line.starts_with(\"*** \") {\n            return Err(anyhow!(\"unexpected patch directive: {raw_line}\"));\n        }\n        if raw_line.starts_with(\"@@\") {\n            continue;\n        }\n\n        let (kind, rest) = raw_line.split_at(1);\n        let content = rest.to_string();\n\n        match kind {\n            \" \" => {\n                let Some(found) = file_lines[cursor..]\n                    .iter()\n                    .position(|line| line == &content)\n                    .map(|offset| cursor + offset)\n                else {\n                    return Err(anyhow!(\n                        \"patch context not found in {}: {}\",\n                        file_path.display(),","sourceCodeStart":686,"sourceCodeEnd":722,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/eval.rs#L686-L722","documentation":"Inside a patch body, lines beginning with `*** ` are directives. Only `*** Begin Patch`, `*** Update File: `, and `*** End Patch` are recognized; any other `*** `-prefixed directive line causes this error naming the offending raw line.","triggerScenarios":"A patch body containing directives other than the supported set, e.g. `*** Add File:` or `*** Delete File:` appearing after the first Update File header, before `*** End Patch`.","commonSituations":"Model emits multi-file patches with additional directives; a second `*** Update File:` in the same patch (unsupported multi-file form); directive typo like `*** Move to:`.","solutions":["Emit one patch per file, containing only `*** Begin Patch`, one `*** Update File:` header, hunks, and `*** End Patch`.","Remove or split out unsupported directives like Add File / Delete File.","Check the offending line printed in the message and correct its spelling or remove it."],"exampleFix":"// before\n*** Begin Patch\n*** Update File: a.rs\n@@\n*** Update File: b.rs\n// after: two separate patches\n*** Begin Patch\n*** Update File: a.rs\n*** End Patch","handlingStrategy":"validation","validationCode":"let allowed = [\"*** Begin Patch\", \"*** End Patch\"];\nfor line in patch.lines() {\n    if line.starts_with(\"*** \") && !allowed.contains(&line) && !line.starts_with(\"*** Update File: \") {\n        eprintln!(\"unsupported directive: {line}\");\n        return;\n    }\n}","typeGuard":null,"tryCatchPattern":"match apply_patch(&root, patch) {\n    Err(e) if e.to_string().starts_with(\"unexpected patch directive\") => {\n        eprintln!(\"split the multi-directive patch into single-Update-File patches\");\n    }\n    other => other?,\n}","preventionTips":["Emit one file per patch; no multi-file patch bodies.","Validate the directive set before applying.","Keep model prompts explicit about the supported directive subset."],"tags":["patch","parsing","eval"],"backgroundTag":"unsupported-operation","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"}