Hmbown/CodeWhale · error · anyhow::Error
unexpected patch directive
Error message
unexpected patch directive: {raw_line} What it means
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.
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.
Example fix
// before *** Begin Patch *** Update File: a.rs @@ *** Update File: b.rs // after: two separate patches *** Begin Patch *** Update File: a.rs *** End Patch
Defensive patterns
Strategy: validation
Validate before calling
let allowed = ["*** Begin Patch", "*** End Patch"];
for line in patch.lines() {
if line.starts_with("*** ") && !allowed.contains(&line) && !line.starts_with("*** Update File: ") {
eprintln!("unsupported directive: {line}");
return;
}
} Try / catch
match apply_patch(&root, patch) {
Err(e) if e.to_string().starts_with("unexpected patch directive") => {
eprintln!("split the multi-directive patch into single-Update-File patches");
}
other => other?,
} Prevention
- 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.
When it happens
Trigger: 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`.
Common situations: 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:`.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- only *** Update File patches are supported
- patch missing *** Begin Patch header
- patch context not found in
- unsupported patch line
- cannot parse exactly one Rust TRUSTED_KEYS table
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/596b0315be31a552.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/eval.rs:704
let file_rel = header
.strip_prefix("*** Update File: ")
.ok_or_else(|| anyhow!("only *** Update File patches are supported"))?;
if file_rel.contains("..") {
return Err(anyhow!("patch path must be workspace-relative"));
}
let file_path = root.join(file_rel);
let original = read_workspace_file(&file_path)?;
let had_trailing_newline = original.ends_with('\n');
let mut file_lines: Vec<String> = original.lines().map(|l| l.to_string()).collect();
let mut cursor = 0usize;
for raw_line in lines {
if raw_line == "*** End Patch" {
break;
}
if raw_line.starts_with("*** ") {
return Err(anyhow!("unexpected patch directive: {raw_line}"));
}
if raw_line.starts_with("@@") {
continue;
}
let (kind, rest) = raw_line.split_at(1);
let content = rest.to_string();
match kind {
" " => {
let Some(found) = file_lines[cursor..]
.iter()
.position(|line| line == &content)
.map(|offset| cursor + offset)
else {
return Err(anyhow!(
"patch context not found in {}: {}",
file_path.display(),View on GitHub (pinned to 73e0f67d83)