Hmbown/CodeWhale · error

unsupported patch line

Error message

unsupported patch line: {raw_line}

What it means

The eval patch applier's line parser recognizes only a fixed set of line prefixes ('-', '+', and context lines matched earlier in the match). Any other raw line terminates the loop with this error, guarding against malformed or truncated patches being silently misapplied.

Solutions

  1. Inspect the failing line (`raw_line`) and strip or pre-process unsupported headers (---, +++, @@) before feeding the patch to the applier.
  2. Fix the patch generator/prompt so it emits only the simplified '-'/'+ '/context line format.
  3. Check that the patch wasn't truncated or mangled (missing leading '-'/'+' on a line).

Example fix

// before: full unified diff fed directly
@@ -1,3 +1,3 @@
// after: pre-strip headers before applying
let body: Vec<&str> = raw.lines().filter(|l| !l.starts_with("@@") && !l.starts_with("---") && !l.starts_with("+++"))...
Defensive patterns

Strategy: validation

Validate before calling

fn is_supported_patch(lines: &[&str]) -> bool {
    lines.iter().all(|l| {
        l.is_empty() || l.starts_with('-') || l.starts_with('+') || l.starts_with(' ')
    })
}

Try / catch

match apply_patch(path, &patch) {
    Err(e) if e.to_string().contains("unsupported patch line") => {
        eprintln!("malformed patch, skipping: {e}");
        // fall back to full-file rewrite or re-request from the model
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling the patch applier with a patch containing a line whose first token is not a supported opcode — e.g. a diff header (---, +++, diff --git), an @@ hunk header, or garbage output from the model that got past prefix stripping.

Common situations: The model emitted a full unified diff (with @@ hunks and ---/+++ headers) instead of the simplified patch format this applier expects; a truncated patch line lost its leading marker; leading whitespace shifted the opcode character.

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


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

Appendix: source

Thrown at crates/tui/src/eval.rs:742

                    ));
                };
                cursor = found + 1;
            }
            "-" => {
                if cursor >= file_lines.len() || file_lines[cursor] != content {
                    return Err(anyhow!(
                        "patch removal mismatch in {}: expected '{}'",
                        file_path.display(),
                        content
                    ));
                }
                file_lines.remove(cursor);
            }
            "+" => {
                file_lines.insert(cursor, content);
                cursor += 1;
            }
            _ => return Err(anyhow!("unsupported patch line: {raw_line}")),
        }
    }

    let mut updated = file_lines.join("\n");
    if had_trailing_newline {
        updated.push('\n');
    }

    fs::write(&file_path, updated)
        .with_context(|| format!("failed to write patched file {}", file_path.display()))
}

fn run_bash(root: &Path, command: &str) -> Result<String> {
    crate::shell_dispatcher::global_dispatcher().run_foreground(command, root)
}

fn truncate_output(value: &str, max_chars: usize) -> String {
    if value.chars().count() <= max_chars {

View on GitHub (pinned to 73e0f67d83)