dianping/cat · error · Error

Expected "{pattern}" at line {line}, col {col}.

Error message

Expected "{pattern}" at line {line}, col {col}.

What it means

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.

Source

Thrown at cat-home/src/main/webapp/assets/js/editor/worker-css.js:1450

    reset: function(){
        if (this._bookmark){
            this._cursor = this._bookmark.cursor;
            this._line = this._bookmark.line;
            this._col = this._bookmark.col;
            delete this._bookmark;
        }
    },
    readTo: function(pattern){

        var buffer = "",
            c;
        while (buffer.length < pattern.length || buffer.lastIndexOf(pattern) != buffer.length - pattern.length){
            c = this.read();
            if (c){
                buffer += c;
            } else {
                throw new Error("Expected \"" + pattern + "\" at line " + this._line  + ", col " + this._col + ".");
            }
        }

        return buffer;

    },
    readWhile: function(filter){

        var buffer = "",
            c = this.read();

        while(c !== null && filter(c)){
            buffer += c;
            c = this.read();
        }

        return buffer;

View on GitHub (pinned to e815e74d4c)

Solutions

  1. Open the reported line/column and add the missing terminator the message names (e.g. close the comment with `*/`).
  2. Check the source file for truncation (compare file size against origin, re-download or re-paste the full content).
  3. 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.
  4. When embedding user CSS, wrap parsing in try/catch and report the message verbatim — it already contains line and column.

Example fix

/* before */
.header { color: red; } /* TODO: fix colors  <- EOF, closing */ lost

/* after */
.header { color: red; } /* TODO: fix colors */
Defensive patterns

Strategy: try-catch

Validate before calling

function looksComplete(css) {
  // cheap pre-flight: catch obviously truncated constructs the reader scans literally
  var open = (css.match(/\/\*/g) || []).length;
  var close = (css.match(/\*\//g) || []).length;
  var braces = (css.match(/\{/g) || []).length - (css.match(/\}/g) || []).length;
  return open === close && braces === 0;
}

Try / catch

try {
  parser.parse(cssText);
} catch (ex) {
  if (ex instanceof SyntaxError || /Expected "/.test(ex.message)) {
    reportParseError(ex.message); // message already has line/col and the missing pattern
    return;
  }
  throw ex;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14). Data as JSON: /api/errors/6fa0c8affe55d370. Report an issue: GitHub.