Repository navigation
Fix empty source window in CssSyntaxError for long lines without end position - #2184
Conversation
CssSyntaxError#showSourceCode() cuts lines longer than 160 characters to a window around the error position. The window end was computed as Math.max(column + padding, endColumn + padding), but errors thrown without an end position (for example tokenizer errors like "Unclosed string" or parser errors like "Unclosed block" and "Missed semicolon") have undefined endColumn. The computation became NaN and line.slice(subLineStart, NaN) returned an empty string, so the output showed an empty error line with the caret pointing at nothing. Fall back to the error column when endColumn is missing. Signed-off-by: simpleqt <[email protected]>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Calculate and test the excerpt window lib/css-syntax-error.js, test/css-syntax-error.test.ts |
showSourceCode falls back to column when endColumn is not numeric. The test checks that an error without a range displays a truncated excerpt, the error marker, and the following line. |
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix
Suggested reviewers: ai
Merge Risk: 
Minimal · up to 9e057
-
The reported long-line rendering issue is addressed with focused regression coverage, and no merge-blocking risk is established.
Pre-merge checks: 
5
-
Full details: Docstring Coverage
-
Explanation
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
|
Thanks |
Problem
CssSyntaxError#showSourceCode()cuts error lines longer than 160 characters to a20-character window around the error position (added in #1965 for minified CSS).
The window end is computed as:
Errors thrown without an end position have
endColumn === undefined. This is thecase for every error created through the two-argument
Input#error(message, line|offset)form, which includes all tokenizer errors (
Unclosed string,Unclosed comment,Unclosed bracket) and parser errors (Unclosed block,Missed semicolon).For those errors
this.endColumn + paddingisNaN,Math.maxreturnsNaN, andline.slice(subLineStart, NaN)returns''. The reportederror.line/error.columnare still correct, but the rendered snippet shows an empty error line with a caret
pointing at nothing:
Output on
main:Output with this fix:
Errors with a range (for example
Unknown word) keep working becauseendColumnis a number there — the existing
cut minified csstests only cover that case.Root cause
The long-line windowing in
lib/css-syntax-error.jsassumesendColumnalwaysexists. It does not for errors created from a single position.
Fix
Fall back to the error column when
endColumnis missing:slice()already clamps to the line length, so the same code path now shows the last20 columns before the error plus everything up to its end.
Reproduction and red/green evidence
New regression test
cuts long line for error without rangeintest/css-syntax-error.test.ts(css = 'a{b:c}\n' + 'x'.repeat(300) + '{content:"\n',Unclosed stringat 2:310, expects the windowed linexxxxxxxxxx{content:"and acaret at column 310).
main(2faedf9) + test only, second worktree:./node_modules/.bin/uvu -r ts-node/register/transpile-only test css-syntax-error→
Total: 26 / Passed: 25, actual> 2 |(empty window).Total: 26 / Passed: 26pnpm unit→Total: 732 / Passed: 732eslint lib/css-syntax-error.js test/css-syntax-error.test.ts→ cleancheck-dts→ cleanNotes
Behavior for errors that have an end position is unchanged; the extra test locks the
no-range path that previously produced the empty window.
Disclosure: prepared and validated by an autonomous AI agent (simpleqt); the defect,
root cause, fix and test were reviewed by the submitting human operator.
Summary by CodeRabbit