dianping/cat · error · ValidationError
Expected ({}) but found '{}'.
Error message
Expected ({}) but found '{}'. What it means
The total-miss branch of `Validation.singleProperty`: no token of the value matched the expected type expression at all (`result` false and the expression is at its first token), so it throws `ValidationError("Expected (" + types + ") but found 'value'")` anchored at the value's position. The message interpolates the internal type expression (e.g. `<length> | <percentage> | inherit`), which is exactly what the property accepts.
Source
Thrown at cat-home/src/main/webapp/assets/js/editor/worker-css.js:5169
var result = false,
value = expression.value,
count = 0,
part;
while (expression.hasNext() && count < max) {
result = ValidationTypes.isAny(expression, types);
if (!result) {
break;
}
count++;
}
if (!result) {
if (expression.hasNext() && !expression.isFirst()) {
part = expression.peek();
throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
} else {
throw new ValidationError("Expected (" + types + ") but found '" + value + "'.", value.line, value.col);
}
} else if (expression.hasNext()) {
part = expression.next();
throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
}
},
multiProperty: function (types, expression, comma, max) {
var result = false,
value = expression.value,
count = 0,
sep = false,
part;
while(expression.hasNext() && !result && count < max) {
if (ValidationTypes.isAny(expression, types)) {View on GitHub (pinned to e815e74d4c)
Solutions
- Read the 'Expected (...)' clause in the message — it lists the accepted types/keywords verbatim; pick a value matching it.
- If the value came from a variable/template, print the rendered CSS and fix the substitution.
- If the keyword is valid modern CSS, upgrade the validator table (see unknown-property solutions) since old tables lack new keywords.
Example fix
/* before */
.layer { z-index: high; } /* Expected (<integer> | auto) but found 'high' */
/* after */
.layer { z-index: 10; } Defensive patterns
Strategy: try-catch
Validate before calling
// mirror the type expression from the error message to pre-check a value you generate
function matchesTypeExpr(types, token) {
// e.g. types='<integer> | auto'
if (/integer|number/.test(types) && /^-?\d+$/.test(token)) return true;
if (/length/.test(types) && /^-?\d+(px|em|rem|%)$/.test(token)) return true;
return types.split('|').map(function (t) { return t.trim(); }).indexOf(token) !== -1;
} Try / catch
try {
Validation.validate(property, value);
} catch (ex) {
if (/^Expected \(/.test(ex.message)) { addLint(ex.line, ex.col, ex.message); return; } // message contains the accepted grammar
throw ex;
} Prevention
- Read the 'Expected (...)' grammar in the message — it enumerates exactly what is accepted.
- For generated CSS, unit-test emitters against the validator's grammar strings.
- Log the rendered value when templating produces values, since substitutions often cause total mismatches.
When it happens
Trigger: `display: foo`, `z-index: high`, `width: lots`, `overflow: sometimes` — the first value token matches none of the allowed types. Any singleProperty-validated property (`spec` string without `||`, or `multi` with `isFirst()` true) given a completely wrong value.
Common situations: Typos and keyword guesses; values copied from a different property; unquoted templating that substitutes an identifier the grammar cannot match; legacy keywords removed from the table.
Related errors
- Expected {name} at line {line}, col {col}.
- Expected end of value but found '{part}'.
- Expected (<'azimuth'>) but found '{}'.
- Expected end of value but found '{}'.
- Expected ([<number> | <percentage>]{1,4} && fill?) but found
AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14).
Data as JSON: /api/errors/061095c91e85c0f5.
Report an issue: GitHub.