{"record":{"id":"0b47ae3d5c873479","repo":"apple/pkl","slug":"invalid-duration-unit-symbol","errorCode":null,"errorMessage":"Invalid Duration unit symbol: ","messagePattern":"Invalid Duration unit symbol: ","errorType":"exception","errorClass":"PklException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/packages/DependencyMetadata.java","lineNumber":265,"sourceCode":"          }\n          var unit = DataSizeUnit.parse(symbol);\n          if (unit == null) {\n            throw new PklException(\"Invalid DataSize unit symbol: \" + symbol);\n          }\n          if (!(value instanceof Double num)) {\n            throw new FormatException(\"double\", value.getClass());\n          }\n          return new DataSize(num, unit);\n        }\n        case \"Duration\" -> {\n          var symbol = jsObj.getString(\"unit\");\n          var value = jsObj.get(\"value\");\n          if (value == null) {\n            throw new MissingFieldException(jsObj, \"value\");\n          }\n          var unit = DurationUnit.parse(symbol);\n          if (unit == null) {\n            throw new PklException(\"Invalid Duration unit symbol: \" + symbol);\n          }\n          if (!(value instanceof Double num)) {\n            throw new FormatException(\"double\", value.getClass());\n          }\n          return new Duration(num, unit);\n        }\n        case \"Pair\" -> {\n          var first = parsePObject(jsObj.get(\"first\"));\n          var second = parsePObject(jsObj.get(\"second\"));\n          return new Pair<>(first, second);\n        }\n      }\n    }\n    // should never be reached\n    throw new PklException(\"Could not read annotation. Invalid object type: \" + obj.getClass());\n  }\n\n  public static Checksums parseChecksums(Object obj) throws JsonParseException {","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/packages/DependencyMetadata.java#L247-L283","documentation":"Thrown by parsePObject when a Duration-typed JSON object carries a \"unit\" symbol that DurationUnit.parse cannot recognize. Valid Pkl duration units are b, ms, s, min, h, d. The library throws because it cannot map the serialized unit back to a DurationUnit enum value.","triggerScenarios":"Parsing metadata JSON like {\"type\":\"Duration\",\"unit\":\"seconds\",\"value\":5.0} — any unit symbol outside {b, ms, s, min, h, d}, including null or an empty string, triggers this.","commonSituations":"Metadata produced by a non-Pkl tool that spelled out unit names (\"seconds\", \"msec\") or used abbreviations like \"us\"/\"ns\" that Pkl does not support.","solutions":["Change the unit symbol to a valid Pkl duration unit: b, ms, s, min, h, or d","Regenerate the metadata file with the official Pkl serializer","Convert the value to a supported unit (e.g. \"seconds\" -> \"s\")"],"exampleFix":"// before\n{\"type\": \"Duration\", \"unit\": \"seconds\", \"value\": 30.0}\n// after\n{\"type\": \"Duration\", \"unit\": \"s\", \"value\": 30.0}","handlingStrategy":"validation","validationCode":"Set<String> VALID = Set.of(\"b\",\"ms\",\"s\",\"min\",\"h\",\"d\");\nboolean hasValidDurationUnit(Object o) {\n  return o instanceof Map<?,?> m && m.get(\"unit\") instanceof String u && VALID.contains(u);\n}","typeGuard":null,"tryCatchPattern":"try {\n  var d = DependencyMetadata.parsePObject(json);\n} catch (PklException e) {\n  if (e.getMessage().startsWith(\"Invalid Duration unit symbol\")) {\n    log.error(\"Unsupported duration unit; use b, ms, s, min, h, or d\", e);\n  }\n}","preventionTips":["Only use Pkl duration unit symbols (b, ms, s, min, h, d) in metadata","Convert spelled-out units (seconds, minutes) to symbols before serializing","Regenerate metadata with the official Pkl serializer rather than custom code"],"tags":["pkl","duration","invalid-enum-value"],"backgroundTag":"invalid-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"}