{"record":{"id":"2aea696695b0f5bd","repo":"apache/cassandra","slug":"ex-getmessage","errorCode":null,"errorMessage":"ex.getMessage()","messagePattern":"ex\\.getMessage\\(\\)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/FormatFcts.java","lineNumber":225,"sourceCode":"                sourceUnit = validateUnit(arguments.get(1));\n                targetUnitAsString = arguments.get(2);\n            }\n\n            targetUnit = validateUnit(targetUnitAsString);\n\n            double convertedValue = convertValue(value, sourceUnit, targetUnit);\n            return UTF8Type.instance.fromString(format(convertedValue) + ' ' + targetUnitAsString);\n        }\n\n        private TimeUnit validateUnit(String unitAsString)\n        {\n            try\n            {\n                return DurationSpec.fromSymbol(unitAsString);\n            }\n            catch (Exception ex)\n            {\n                throw new InvalidRequestException(ex.getMessage());\n            }\n        }\n\n        private Pair<Double, String> convertValue(long valueToConvert)\n        {\n            for (int i = 0; i < CONVERSION_FACTORS.length; i++)\n            {\n                if (valueToConvert >= CONVERSION_FACTORS[i])\n                {\n                    double convertedValue = (double) valueToConvert / CONVERSION_FACTORS[i];\n                    return Pair.create(convertedValue, UNITS[i]);\n                }\n            }\n            return Pair.create((double) valueToConvert, \"ms\");\n        }\n\n        private Double convertValue(long valueToConvert, TimeUnit sourceUnit, TimeUnit targetUnit)\n        {","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/FormatFcts.java#L207-L243","documentation":"Time duration format functions validate the unit argument via DurationSpec.fromSymbol, which only accepts Cassandra's duration units (e.g. 'years', 'months', 'days', 'hours', 'minutes', 'seconds', etc.). validateUnit() wraps any exception from that parsing and rethrows its message as an InvalidRequestException. This error means the unit string supplied is not a recognized duration unit symbol.","triggerScenarios":"Executing a duration format function (e.g. formatDuration(...)) where the unit parameter is misspelled, plural/singular mismatched, or an unsupported string like 'yrs' or 'seconds*' — any Exception from DurationSpec.fromSymbol is rethrown.","commonSituations":"Typos in cqlsh queries; assuming abbreviated units ('h', 'sec') are supported; version differences where certain unit symbols are not accepted.","solutions":["Use an exact supported unit symbol, e.g. 'years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds', 'nanoseconds' (check DurationSpec symbols for your version).","Check the function's documentation/description in system_schema or DESCRIPTOR for accepted units.","Correct casing/plurality to match the enum symbol exactly."],"exampleFix":"// before\nSELECT formatDuration(90, 'min') FROM t;\n// after\nSELECT formatDuration(90, 'minutes') FROM t;","handlingStrategy":"validation","validationCode":"Set<String> allowed = Set.of(\"years\",\"months\",\"weeks\",\"days\",\"hours\",\"minutes\",\"seconds\",\"milliseconds\",\"microseconds\",\"nanoseconds\");\nif (!allowed.contains(unit)) throw new IllegalArgumentException(\"bad duration unit: \" + unit);","typeGuard":null,"tryCatchPattern":"try { session.execute(\"SELECT formatDuration(90, '\" + unit + \"') FROM t\"); } catch (InvalidRequestException e) { /* unit symbol rejected — correct and retry with canonical symbol */ }","preventionTips":["Use exact DurationSpec symbols, fully spelled out and plural where required","Keep unit names in a constants file shared across queries","Check DESC FUNCTION output for accepted units"],"tags":["cql","invalid-enum-value","duration"],"backgroundTag":"invalid-enum-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}