can1357/oh-my-pi · error · ParseError
Line hint must be >= 1
Error message
Line hint must be >= 1
What it means
Thrown when an '@@' change-context header carries a line hint (e.g. '@@ near line 0') parsed by LINE_HINT_REGEX and the extracted hint is less than 1. Line hints resolve ambiguous context markers to a concrete anchor line, and the parser enforces 1-based positive numbering just like unified headers. It fails fast at the header line rather than mis-anchoring the patch.
Source
Thrown at packages/coding-agent/src/edit/diff.ts:594
throw new ParseError("Line numbers in @@ header must be >= 1", lineNumber);
}
if (unifiedHeader.changeContext) {
changeContexts.push(unifiedHeader.changeContext);
}
oldStartLine = unifiedHeader.oldStartLine;
newStartLine = unifiedHeader.newStartLine;
startIndex = 1;
} else if (isHeaderLine && headerTrimmed.startsWith(CHANGE_CONTEXT_MARKER)) {
const contextValue = headerTrimmed.slice(CHANGE_CONTEXT_MARKER.length);
const trimmedContextValue = contextValue.trim();
const normalizedContextValue = trimmedContextValue.replace(/^@@\s*/u, "");
const lineHintMatch = normalizedContextValue.match(LINE_HINT_REGEX);
if (lineHintMatch) {
oldStartLine = Number(lineHintMatch[1]);
newStartLine = oldStartLine;
if (oldStartLine < 1) {
throw new ParseError("Line hint must be >= 1", lineNumber);
}
} else if (TOP_OF_FILE_REGEX.test(normalizedContextValue)) {
oldStartLine = 1;
newStartLine = 1;
} else if (trimmedContextValue.length > 0) {
changeContexts.push(contextValue);
}
startIndex = 1;
} else if (isHeaderLine) {
const contextValue = headerTrimmed.slice(2).trim();
if (contextValue.length > 0) {
changeContexts.push(contextValue);
}
startIndex = 1;
} else {
if (!allowMissingContext) {
throw new ParseError(`Expected hunk to start with @@ context marker, got: '${lines[0]}'`, lineNumber);
}View on GitHub (pinned to 9690622007)
Solutions
- Change the line hint to 1-based: use 'line 1' or a top-of-file marker instead of 'line 0'.
- Drop the line hint entirely and let the surrounding context text locate the hunk.
- Fix the generating code to add 1 when converting from 0-based indices.
- Pre-validate header hints with a regex before calling the parser.
Example fix
// before @@ src/app.ts line 0 // after @@ src/app.ts line 1
Defensive patterns
Strategy: validation
Validate before calling
const hint = contextHeader.match(/line\s+(-?\d+)/i);
if (hint && Number(hint[1]) < 1) {
throw new Error(`Line hint must be >= 1, got ${hint[1]}; use 'line 1' or top-of-file`);
} Try / catch
try {
hunks = parseDiffHunks(diff);
} catch (err) {
if (err instanceof ParseError && err.message === "Line hint must be >= 1") {
// rewrite 'line 0' hints to 'line 1' and retry once
} else throw err;
} Prevention
- Emit 1-based line hints; map 'line 0' meaning top-of-file to a top-of-file marker.
- Prefer anchoring hunks with surrounding context text instead of numeric hints.
- Add 1 when converting from 0-based indices in generator code.
When it happens
Trigger: Calling parseDiffHunks on a patch whose context header contains a line hint of 0 or negative, e.g. '@@ foo.js line 0' or '@@ near line -2'.
Common situations: LLM- or template-generated patches where a 'line 0' hint means 'top of file'; scripts that compute hint line numbers with 0-based indices; hand-edited patches after copy/paste.
Related errors
- Line numbers in @@ header must be >= 1
- Line numbers must be >= 1 (got ${oldStartLine})
- Line numbers must be >= 1 (got ${newStartLine})
- Unknown changelog category: ${raw}
- No JSON payload found in response
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/02b940009141c76a.
Report an issue: GitHub.