{"record":{"id":"6fa0c8affe55d370","repo":"dianping/cat","slug":"expected-pattern-at-line-line-col-col","errorCode":null,"errorMessage":"Expected \"{pattern}\" at line {line}, col {col}.","messagePattern":"Expected \"(.+?)\" at line (.+?), col (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cat-home/src/main/webapp/assets/js/editor/worker-css.js","lineNumber":1450,"sourceCode":"\n    reset: function(){\n        if (this._bookmark){\n            this._cursor = this._bookmark.cursor;\n            this._line = this._bookmark.line;\n            this._col = this._bookmark.col;\n            delete this._bookmark;\n        }\n    },\n    readTo: function(pattern){\n\n        var buffer = \"\",\n            c;\n        while (buffer.length < pattern.length || buffer.lastIndexOf(pattern) != buffer.length - pattern.length){\n            c = this.read();\n            if (c){\n                buffer += c;\n            } else {\n                throw new Error(\"Expected \\\"\" + pattern + \"\\\" at line \" + this._line  + \", col \" + this._col + \".\");\n            }\n        }\n\n        return buffer;\n\n    },\n    readWhile: function(filter){\n\n        var buffer = \"\",\n            c = this.read();\n\n        while(c !== null && filter(c)){\n            buffer += c;\n            c = this.read();\n        }\n\n        return buffer;\n","sourceCodeStart":1432,"sourceCodeEnd":1468,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-home/src/main/webapp/assets/js/editor/worker-css.js#L1432-L1468","documentation":"Thrown by the CSS worker's low-level `StringReader.readTo(pattern)`, which reads characters until an exact string (the expected `pattern`) is consumed. If the input stream ends (the reader's `read()` returns null) before the pattern appears, the parser knows only that it hit EOF while looking for a fixed token, so it throws with the current line/column. This is a hard syntax error in the tokenization phase, before any CSS structure is interpreted.","triggerScenarios":"Feeding `parse(input)` a stylesheet that is truncated inside a construct the reader scans literally — typically an unterminated block comment (missing closing `*/`) or a truncated string/url the reader is scanning to a literal terminator; a file cut off mid-upload; a network response clipped so the tail containing the expected pattern never arrives.","commonSituations":"Editing in the code editor when the CSS file is saved mid-keystroke; partial file reads (file watcher firing during write); pasting CSS that got clipped at a length limit; concatenating CSS with a build tool that drops the closing comment marker.","solutions":["Open the reported line/column and add the missing terminator the message names (e.g. close the comment with `*/`).","Check the source file for truncation (compare file size against origin, re-download or re-paste the full content).","If the input is produced by a build step, validate the emitted CSS with a linter so the truncated artifact is caught at build time.","When embedding user CSS, wrap parsing in try/catch and report the message verbatim — it already contains line and column."],"exampleFix":"/* before */\n.header { color: red; } /* TODO: fix colors  <- EOF, closing */ lost\n\n/* after */\n.header { color: red; } /* TODO: fix colors */","handlingStrategy":"try-catch","validationCode":"function looksComplete(css) {\n  // cheap pre-flight: catch obviously truncated constructs the reader scans literally\n  var open = (css.match(/\\/\\*/g) || []).length;\n  var close = (css.match(/\\*\\//g) || []).length;\n  var braces = (css.match(/\\{/g) || []).length - (css.match(/\\}/g) || []).length;\n  return open === close && braces === 0;\n}","typeGuard":null,"tryCatchPattern":"try {\n  parser.parse(cssText);\n} catch (ex) {\n  if (ex instanceof SyntaxError || /Expected \"/.test(ex.message)) {\n    reportParseError(ex.message); // message already has line/col and the missing pattern\n    return;\n  }\n  throw ex;\n}","preventionTips":["Validate comment open/close counts before parsing untrusted or streamed CSS.","Never parse a file mid-write — wait for the writer to finish (write-then-rename pattern).","Run CSSLint on generated CSS in CI to catch truncation at build time.","Treat the embedded line/col in the message as authoritative for jump-to-error UI."],"tags":["css","parser","tokenizer","eof","syntax-error"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}