{"record":{"id":"8be1a11df8a4fda0","repo":"apple/pkl","slug":"invalid-datasize-unit-s","errorCode":null,"errorMessage":"Invalid DataSize unit `%s`","messagePattern":"Invalid DataSize unit `(.+?)`","errorType":"validation","errorClass":"DecodeException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/util/pklbinary/AbstractPklBinaryDecoder.java","lineNumber":285,"sourceCode":"    var rawDurationUnit = unpacker.unpackString();\n    var durationUnit = DurationUnit.parse(rawDurationUnit);\n    if (durationUnit == null) {\n      throw new DecodeException(\"Invalid Duration unit `%s`\", rawDurationUnit);\n    }\n    var result = doDecodeDuration(durationValue, durationUnit);\n    unpacker.skipValue(len - 3);\n    currPath.pop();\n    return result;\n  }\n\n  private Object decodeDataSize(int len) throws IOException {\n    assertLength(PklBinaryCode.DATASIZE, len, 2);\n    currPath.push(\"'datasize\");\n    var dataSizeValue = unpacker.unpackDouble();\n    var rawDataSizeUnit = unpacker.unpackString();\n    var dataSizeUnit = DataSizeUnit.parse(rawDataSizeUnit);\n    if (dataSizeUnit == null) {\n      throw new DecodeException(\"Invalid DataSize unit `%s`\", rawDataSizeUnit);\n    }\n    var result = doDecodeDataSize(dataSizeValue, dataSizeUnit);\n    unpacker.skipValue(len - 3);\n    currPath.pop();\n    return result;\n  }\n\n  private Object decodePair(int len) throws IOException {\n    assertLength(PklBinaryCode.PAIR, len, 2);\n    currPath.push(\"'pair\");\n    currPath.push(\"'first\");\n    var first = doDecode();\n    currPath.pop();\n    currPath.push(\"'second\");\n    var second = doDecode();\n    currPath.pop();\n    var result = doDecodePair(first, second);\n    unpacker.skipValue(len - 3);","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/util/pklbinary/AbstractPklBinaryDecoder.java#L267-L303","documentation":"Thrown by decodeDataSize when a DATASIZE entry's unit string cannot be parsed by DataSizeUnit.parse. Pkl data sizes only accept canonical units (b, kb, mb, gb, tb, pb, kib, mib, gib, tib, pib); anything else makes the payload invalid.","triggerScenarios":"Decoding pkl-binary bytes where a DATASIZE entry has a unit like \"kilobytes\", \"KB\", or an empty string; a custom encoder writing non-canonical or wrongly-cased unit names.","commonSituations":"Encoders emitting display-style unit names; hand-edited binary fixtures; case-sensitivity mismatches when a producer upper-cases units.","solutions":["Use canonical Pkl DataSize unit strings (lowercase b/kb/mb/... /kib/mib/...) in the encoder","Normalize unit names at the producer before packing","Regenerate the payload with the official Pkl encoder","Check the raw string logged in the message and fix the producer mapping"],"exampleFix":"// before\npacker.packString(\"KB\");\n// after\npacker.packString(\"kb\");","handlingStrategy":"validation","validationCode":"Set<String> VALID = Set.of(\"b\",\"kb\",\"mb\",\"gb\",\"tb\",\"pb\",\"kib\",\"mib\",\"gib\",\"tib\",\"pib\");\nif (!VALID.contains(unit)) throw new IllegalArgumentException(\"bad datasize unit: \" + unit);","typeGuard":null,"tryCatchPattern":"try {\n  return decoder.decode(bytes);\n} catch (DecodeException e) {\n  if (e.getMessage().contains(\"Invalid DataSize unit\")) {\n    throw new MalformedPklBinaryException(e);\n  }\n  throw e;\n}","preventionTips":["Use lowercase canonical DataSize units in binary payloads","Avoid display formatting (e.g. \"KB\", \"MiB\") at the encoder boundary","Round-trip test all units","Validate units before packing"],"tags":["pkl","binary-decoder","datasize","enum"],"backgroundTag":"unsupported-enum-value","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}