dianping/cat · error · RuntimeException
Invalid level.
Error message
Invalid level.
What it means
LogLevel.getName(int) throws RuntimeException("Invalid level.") when the id matches no LogLevel enum constant. LogLevel maps log-level ids to names for CAT's log-viewing features. Note it uses ids, not the character codes some other CAT enums use — passing a wrong identifier type is a classic cause.
Source
Thrown at cat-core/src/main/java/com/dianping/cat/config/LogLevel.java:43
ERROR(2, "error");
private int m_id;
private String m_level;
private LogLevel(int id, String level) {
m_id = id;
m_level = level;
}
public static String getName(int id) {
for (LogLevel logLevel : LogLevel.values()) {
if (logLevel.getId() == id) {
return logLevel.getLevel();
}
}
throw new RuntimeException("Invalid level.");
}
public static int getId(String level) {
for (LogLevel logLevel : LogLevel.values()) {
if (logLevel.getLevel().equalsIgnoreCase(level)) {
return logLevel.getId();
}
}
throw new RuntimeException("Invalid level.");
}
public int getId() {
return m_id;
}
public String getLevel() {
return m_level;View on GitHub (pinned to e815e74d4c)
Solutions
- Log the id at the call site; compare with the id values declared in the LogLevel enum.
- Validate the id range before calling, or scan LogLevel.values() for a match and fall back to a default name.
- If ids come from remote data, pin client and server to matching versions or send names instead of ids.
- Fix upstream parsing so uninitialized ids never reach this mapping.
Example fix
// before
String level = LogLevel.getName(event.getLevelId()); // id 99 -> throws
// after
int id = event.getLevelId();
String level = null;
for (LogLevel l : LogLevel.values()) { if (l.getId() == id) { level = l.getLevel(); break; } }
if (level == null) level = "UNKNOWN"; Defensive patterns
Strategy: validation
Validate before calling
boolean ok = false;
for (LogLevel l : LogLevel.values()) if (l.getId() == id) { ok = true; break; }
if (!ok) id = defaultId; Prevention
- Do not confuse char level codes with numeric enum ids.
- Pin client/server versions that share the id scheme.
When it happens
Trigger: LogLevel.getName(id) with an id outside the enum's defined ids — e.g. a char value accidentally passed as an int ('E' = 69), -1 from a lookup failure upstream, or an id from a newer/older schema.
Common situations: Version skew between the CAT server and stored/forwarded log data, passing an ASCII char code where a numeric enum id was expected, or default int values (0/-1) from unparsed fields reaching this call.
Related errors
- Unsupported MetricType Name!
- Invalid level
- 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/1119cf8c32c1a4a5.
Report an issue: GitHub.