{"record":{"id":"8f93c64f755c6c2e","repo":"dianping/cat","slug":"unsupported-metrictype-name","errorCode":null,"errorMessage":"Unsupported MetricType Name!","messagePattern":"Unsupported MetricType Name!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"cat-core/src/main/java/com/dianping/cat/helper/MetricType.java","lineNumber":43,"sourceCode":"\n\tSUM(\"SUM\", \"(总和)\");\n\n\tprivate String m_name;\n\n\tprivate String m_desc;\n\n\tMetricType(String name, String desc) {\n\t\tm_name = name;\n\t\tm_desc = desc;\n\t}\n\n\tpublic static MetricType getTypeByName(String name) {\n\t\tfor (MetricType type : MetricType.values()) {\n\t\t\tif (type.getName().equals(name)) {\n\t\t\t\treturn type;\n\t\t\t}\n\t\t}\n\t\tthrow new RuntimeException(\"Unsupported MetricType Name!\");\n\t}\n\n\tpublic static String getDesByName(String name) {\n\t\tfor (MetricType type : MetricType.values()) {\n\t\t\tif (type.getName().equals(name)) {\n\t\t\t\treturn type.getDesc();\n\t\t\t}\n\t\t}\n\t\tthrow new RuntimeException(\"Unsupported MetricType Name!\");\n\t}\n\n\tpublic String getName() {\n\t\treturn m_name;\n\t}\n\n\tpublic String getDesc() {\n\t\treturn m_desc;\n\t}","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/dianping/cat/blob/e815e74d4c2dd74edac831241f1253fcc7d25381/cat-core/src/main/java/com/dianping/cat/helper/MetricType.java#L25-L61","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Print the name argument at the call site (the exception text omits it).","Align the name with the enum constants' exact spelling; check the MetricType source for the supported set.","For cross-version deployments, upgrade cat-core to at least the client's version so new metric types exist.","Pre-filter unknown names via a helper over MetricType.values() and skip/log them instead of crashing."],"exampleFix":"// before\nMetricType t = MetricType.getTypeByName(metricName); // 'url' -> throws\n\n// after\nString name = metricName == null ? null : metricName.toUpperCase();\nMetricType t = name == null ? null : MetricType.getTypeByName(name);","handlingStrategy":"validation","validationCode":"public static boolean isKnownMetricType(String name) {\n    for (MetricType t : MetricType.values()) if (t.getName().equals(name)) return true;\n    return false;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Upper-case/trim metric names before lookup.","Upgrade cat-core in lockstep with cat-client metric vocabulary."],"tags":["enum","metrics","validation","versioning"],"backgroundTag":null,"analyzedSha":"e815e74d4c2dd74edac831241f1253fcc7d25381","analyzedAt":"2026-08-14T14:22:34.512Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}