apple/pkl · error · PklException
Invalid DataSize unit symbol:
Error message
Invalid DataSize unit symbol:
What it means
PklException("Invalid DataSize unit symbol: " + symbol) is thrown by DependencyMetadata.parsePObject when the `unit` field of a DataSize value is not a recognized DataSizeUnit symbol (e.g. "b", "kb", "mb", "gb", "tb"...). An unrecognized symbol means the metadata cannot construct a DataSize. It indicates a typo or wrong-casing in the unit symbol.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/packages/DependencyMetadata.java:250
var properties = new HashMap<String, Object>();
for (var kv : props.entrySet()) {
properties.put(kv.getKey(), parsePObject(kv.getValue()));
}
return new PObject(classInfo, properties);
}
case "Pattern" -> {
var value = jsObj.getString("value");
return Pattern.compile(value);
}
case "DataSize" -> {
var symbol = jsObj.getString("unit");
var value = jsObj.get("value");
if (value == null) {
throw new MissingFieldException(jsObj, "value");
}
var unit = DataSizeUnit.parse(symbol);
if (unit == null) {
throw new PklException("Invalid DataSize unit symbol: " + symbol);
}
if (!(value instanceof Double num)) {
throw new FormatException("double", value.getClass());
}
return new DataSize(num, unit);
}
case "Duration" -> {
var symbol = jsObj.getString("unit");
var value = jsObj.get("value");
if (value == null) {
throw new MissingFieldException(jsObj, "value");
}
var unit = DurationUnit.parse(symbol);
if (unit == null) {
throw new PklException("Invalid Duration unit symbol: " + symbol);
}
if (!(value instanceof Double num)) {
throw new FormatException("double", value.getClass());View on GitHub (pinned to f3efcbfc9b)
Solutions
- Use a valid Pkl DataSize unit symbol with correct casing, e.g. "kb", "mb", "gb" (or binary variants like "kib", "mib").
- Regenerate the metadata with `pkl project package` so units are serialized canonically.
- Check DataSizeUnit.parse for the exact accepted symbol list and match it.
- Fall back to the base unit (e.g. convert to "b" bytes) if unsure.
Example fix
// before
{"type": "DataSize", "unit": "MB", "value": 10.0}
// after
{"type": "DataSize", "unit": "mb", "value": 10.0} Defensive patterns
Strategy: validation
Validate before calling
var validUnits = java.util.Set.of("b","kb","mb","gb","tb","pb","kib","mib","gib","tib","pib");
var unit = entry.get("unit").asString();
if (!validUnits.contains(unit)) throw new IllegalStateException("Unknown DataSize unit symbol: " + unit); Prevention
- Use canonical lowercase Pkl unit symbols (b, kb, mb, ... and kib, mib, ...); check DataSizeUnit.parse for the exact list.
- Never write human forms like "MB" or "megabytes" into metadata.
- Let the packaging tool serialize units instead of typing them manually.
- Add unit-symbol validation to your metadata linter.
When it happens
Trigger: Parsing metadata with a DataSize entry whose `unit` is an unknown string such as "MB", "megabytes", "kib", or an empty string.
Common situations: Hand-written annotations using human unit names; case-sensitivity mistakes ("MB" vs "mb"); confusion between binary unit families supported by Pkl's DataSizeUnit.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/0e6bfd7611907589.
Report an issue: GitHub.