can1357/oh-my-pi · error · ParseError

Hunk does not contain any lines

Error message

Hunk does not contain any lines

What it means

Thrown when, after consuming the '@@' header and any nested change-context lines, the parser has run past the end of the input without finding a single content line. A hunk header with no body is meaningless — there is nothing to apply — so the parser rejects it, reporting the first missing content position (header line + 1).

Source

Thrown at packages/coding-agent/src/edit/diff.ts:643

		if (!nextLine.startsWith("@@")) {
			break;
		}
		const trimmed = nextLine.trimEnd();
		if (trimmed.startsWith(CHANGE_CONTEXT_MARKER)) {
			const nestedContext = trimmed.slice(CHANGE_CONTEXT_MARKER.length);
			if (nestedContext.trim().length > 0) {
				changeContexts.push(nestedContext);
			}
			startIndex++;
		} else if (trimmed === EMPTY_CHANGE_CONTEXT_MARKER) {
			startIndex++;
		} else {
			break;
		}
	}

	if (startIndex >= lines.length) {
		throw new ParseError("Hunk does not contain any lines", lineNumber + 1);
	}

	const changeContext = changeContexts.length > 0 ? changeContexts.join("\n") : undefined;

	const hunk: DiffHunk = {
		changeContext,
		oldStartLine,
		newStartLine,
		hasContextLines: false,
		oldLines: [],
		newLines: [],
		isEndOfFile: false,
	};

	let parsedLines = 0;

	for (let i = startIndex; i < lines.length; i++) {
		const line = lines[i];

View on GitHub (pinned to 9690622007)

Solutions

  1. Append the missing hunk body (at least one ' ', '+', or '-' line) after the header.
  2. Check the diff source for truncation — verify the patch file/stream is complete.
  3. If the hunk is intentionally empty, remove the header entirely rather than shipping a bare '@@' line.
  4. Validate that diff.split('\n') has content after each header before parsing.

Example fix

// before
@@ -1,3 +1,3 @@
<end of diff>
// after
@@ -1,3 +1,3 @@
-old value
+new value
Defensive patterns

Strategy: validation

Validate before calling

const lines = diff.split("\n");
lines.forEach((l, i) => {
  if (l.startsWith("@@") && (lines[i + 1] === undefined || lines[i + 1].startsWith("@@"))) {
    throw new Error(`Header at diff line ${i + 1} has no body`);
  }
});

Try / catch

try {
  hunks = parseDiffHunks(diff);
} catch (err) {
  if (err instanceof ParseError && err.message === "Hunk does not contain any lines") {
    // check patch source for truncation; request a regenerated patch
  } else throw err;
}

Prevention

When it happens

Trigger: Calling parseDiffHunks on input that ends immediately after an '@@ ...' header (or after header + context markers), e.g. a diff string ending in '@@ -1,3 +1,3 @@' with no following +/-/space lines.

Common situations: Truncated patches from interrupted file writes or clipped LLM output; copy/paste that dropped the body; templates where the body variable was empty.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/e3e31a00030f9348. Report an issue: GitHub.