dianping/cat · error · RuntimeException

Unsupported MetricType Name!

Error message

Unsupported MetricType Name!

What it means

MetricType.getTypeByName(String) throws RuntimeException("Unsupported MetricType Name!") when the name equals no MetricType enum constant (the metric kinds such as URL/SQL/Cache etc. used in CAT metric reports). The message does not include the offending name, so you must log the argument separately.

Source

Thrown at cat-core/src/main/java/com/dianping/cat/helper/MetricType.java:43

	SUM("SUM", "(总和)");

	private String m_name;

	private String m_desc;

	MetricType(String name, String desc) {
		m_name = name;
		m_desc = desc;
	}

	public static MetricType getTypeByName(String name) {
		for (MetricType type : MetricType.values()) {
			if (type.getName().equals(name)) {
				return type;
			}
		}
		throw new RuntimeException("Unsupported MetricType Name!");
	}

	public static String getDesByName(String name) {
		for (MetricType type : MetricType.values()) {
			if (type.getName().equals(name)) {
				return type.getDesc();
			}
		}
		throw new RuntimeException("Unsupported MetricType Name!");
	}

	public String getName() {
		return m_name;
	}

	public String getDesc() {
		return m_desc;
	}

View on GitHub (pinned to e815e74d4c)

Solutions

  1. Print the name argument at the call site (the exception text omits it).
  2. Align the name with the enum constants' exact spelling; check the MetricType source for the supported set.
  3. For cross-version deployments, upgrade cat-core to at least the client's version so new metric types exist.
  4. Pre-filter unknown names via a helper over MetricType.values() and skip/log them instead of crashing.

Example fix

// before
MetricType t = MetricType.getTypeByName(metricName); // 'url' -> throws

// after
String name = metricName == null ? null : metricName.toUpperCase();
MetricType t = name == null ? null : MetricType.getTypeByName(name);
Defensive patterns

Strategy: validation

Validate before calling

public static boolean isKnownMetricType(String name) {
    for (MetricType t : MetricType.values()) if (t.getName().equals(name)) return true;
    return false;
}

Prevention

When it happens

Trigger: MetricType.getTypeByName(name) with a null, differently-cased, or unknown metric kind — e.g. 'url' when the enum constant is 'URL', or a new metric name introduced by a newer agent than the server understands.

Common situations: Version skew: a newer cat-client emits a metric type the older cat-core enum lacks; user-built metrics pushed with ad-hoc names; case mismatches between what the report layer stores and the enum constant spelling.

Related errors


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