{"record":{"id":"c24ef47ab958763e","repo":"apache/cassandra","slug":"unsupported-target-unit-targetunit","errorCode":null,"errorMessage":"unsupported target unit <targetUnit>","messagePattern":"unsupported target unit <targetUnit>","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/FormatFcts.java","lineNumber":413,"sourceCode":"            String convertedValueAsString = format(convertedValue);\n\n            return UTF8Type.instance.fromString(convertedValueAsString + ' ' + targetUnit.getSymbol());\n        }\n\n        private double convertValue(long valueToConvert, DataStorageUnit sourceUnit, DataStorageUnit targetUnit)\n        {\n            switch (targetUnit)\n            {\n                case BYTES:\n                    return sourceUnit.toBytesDouble(valueToConvert);\n                case KIBIBYTES:\n                    return sourceUnit.toKibibytesDouble(valueToConvert);\n                case MEBIBYTES:\n                    return sourceUnit.toMebibytesDouble(valueToConvert);\n                case GIBIBYTES:\n                    return sourceUnit.toGibibytesDouble(valueToConvert);\n                default:\n                    throw new InvalidRequestException(\"unsupported target unit \" + targetUnit);\n            }\n        }\n\n        private DataStorageUnit validateUnit(String unitAsString)\n        {\n            try\n            {\n                return DataStorageUnit.fromSymbol(unitAsString);\n            }\n            catch (Exception ex)\n            {\n                throw new InvalidRequestException(ex.getMessage());\n            }\n        }\n\n        public static FunctionFactory factory()\n        {\n            return new FunctionFactory(FUNCTION_NAME,","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/FormatFcts.java#L395-L431","documentation":"Data-storage format functions convert a byte/size value into a target unit via a switch over DataStorageUnit enum constants. If the target unit is not one of the handled enum cases, convertValue() throws this InvalidRequestException. It indicates the requested conversion unit fell through the switch default — effectively an internal unsupported-unit condition.","triggerScenarios":"Invoking a storage-size format function with a convertedValue path whose target unit is not bytes/kibibytes/mebibytes/gibibytes-and-siblings handled by the switch — normally only reachable if a new DataStorageUnit enum constant exists but the conversion switch was not updated.","commonSituations":"Running a newer Cassandra version where DataStorageUnit gained a constant but the format function's switch lags; custom patches to the enum.","solutions":["Use a supported target unit symbol (bytes, kilobytes/kibibytes, megabytes/mebibytes, gigabytes/gibibytes, etc. per DataStorageUnit).","Upgrade/patch so the format function's convertValue switch covers the enum constant (report as a bug if hit on stock Cassandra).","Verify the unit string parses to a DataStorageUnit via DataStorageUnit.fromSymbol before calling."],"exampleFix":"// before\nSELECT formatSize(size, 'zebibytes') FROM t; -- unhandled target unit\n// after\nSELECT formatSize(size, 'gibibytes') FROM t;","handlingStrategy":"validation","validationCode":"if (!Set.of(\"bytes\",\"kilobytes\",\"kibibytes\",\"megabytes\",\"mebibytes\",\"gigabytes\",\"gibibytes\").contains(unit)) throw new IllegalArgumentException(\"unsupported target unit: \" + unit);","typeGuard":null,"tryCatchPattern":"try { session.execute(query); } catch (InvalidRequestException e) { if (e.getMessage().startsWith(\"unsupported target unit\")) { /* switch to a supported unit */ } else throw e; }","preventionTips":["Stick to units supported by your Cassandra version's DataStorageUnit enum","Pin the Cassandra version and test format functions after upgrades","Report stock-Cassandra occurrences as bugs (enum/switch drift)"],"tags":["cql","unsupported-operation","units"],"backgroundTag":"unsupported-operation","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}