dianping/cat · error · ParseException
not match %s
Error message
not match %s
What it means
Thrown by DefaultFormat.parse when the input string's length does not equal the length declared after ':' in the pattern (e.g. pattern 'md5:32' but input has 31 characters). This is a strict length check applied before the item-specific validation; it throws java.text.ParseException with 'not match <pattern>'.
Source
Thrown at cat-core/src/main/java/com/dianping/cat/config/DefaultFormat.java:47
public String parse(String input) throws ParseException {
String pattern = getPattern();
String item = "";
String describe = "";
int index = pattern.indexOf(":");
if (index != -1 && pattern.length() > index + 1) {
item = pattern.substring(0, index).trim();
describe = pattern.substring(index + 1).trim();
}
if (!describe.isEmpty()) {
int length = 1;
try {
length = Integer.parseInt(describe);
} catch (NumberFormatException e) {
throw new ParseException(pattern + "is illegal", 0);
}
if (input.length() != length) {
throw new ParseException("not match " + pattern, 0);
}
}
if (pattern.equals("*")) {
return input;
} else if (item.equals("md5")) {
char[] charArray = input.toCharArray();
for (Character ch : charArray) {
if (!Character.isDigit(ch) && !Character.isLowerCase(ch)) {
return input;
}
}
} else if (item.equals("number")) {
char[] charArray = input.toCharArray();
for (Character ch : charArray) {
if (!Character.isDigit(ch)) {
return input;
}
}View on GitHub (pinned to e815e74d4c)
Solutions
- Print the input and pattern from the exception context; compare input.length() with the declared length.
- Fix the data producer if the token is genuinely malformed (e.g. re-generate the full 32-char md5).
- Adjust the pattern length to match the real token width if the config width was wrong.
- Remove the length constraint (drop ':N') if the field is variable-width and only type checking (md5/number) is needed.
Example fix
// before
format.parse("d41d8cd98f00b204e9800998ecf8427", "md5:32"); // 31 chars -> not match
// after
format.parse("d41d8cd98f00b204e9800998ecf8427e", "md5:32"); // full 32-char md5 Defensive patterns
Strategy: validation
Validate before calling
int colon = pattern.indexOf(':');
if (colon > -1 && pattern.length() > colon + 1) {
int want = Integer.parseInt(pattern.substring(colon + 1));
if (input.length() != want) skipOrLog(pattern, input);
} Try / catch
catch (ParseException e) { /* length mismatch: skip bad record, count it, keep batch alive */ } Prevention
- Validate record widths at ingestion before format parsing.
- Monitor skip counters so upstream data drift is visible early.
When it happens
Trigger: DefaultFormat.parse(input, "name:N") where input.length() != N. Typical: 'md5:32' fed a truncated hash, 'number:4' fed a 3-digit cluster, or fixed-width tokens read from a path where one segment lost or gained characters.
Common situations: Parsing URL paths or message-id components against a fixed-width format where data is malformed (lowercase md5 of wrong length, zero-padded fields stripped), or a format config updated to a new width while the data still has the old width.
Related errors
- %sis illegal
- Invalid message ID format: %s
- Expected {name} at line {line}, col {col}.
- Expected end of value but found '{part}'.
- Expected (<'azimuth'>) but found '{}'.
AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14).
Data as JSON: /api/errors/b5e3089eda988177.
Report an issue: GitHub.