{"record":{"id":"ef16c5c3ac926eae","repo":"apple/pkl","slug":"object","errorCode":null,"errorMessage":"object","messagePattern":"object","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ImportGraph.java","lineNumber":76,"sourceCode":"    var imports = parseImports(parsed.getObject(\"imports\"));\n    var resolvedImports = parseResolvedImports(parsed.getObject(\"resolvedImports\"));\n    return new ImportGraph(imports, resolvedImports);\n  }\n\n  private static Map<URI, Set<Import>> parseImports(Json.JsObject jsObject)\n      throws JsonParseException {\n    var ret = new TreeMap<URI, Set<Import>>();\n    for (var entry : jsObject.entrySet()) {\n      try {\n        var key = new URI(entry.getKey());\n        var value = entry.getValue();\n        var set = new TreeSet<Import>();\n        if (!(value instanceof JsArray array)) {\n          throw new FormatException(\"array\", value == null ? Void.class : value.getClass());\n        }\n        for (var elem : array) {\n          if (!(elem instanceof JsObject importObj)) {\n            throw new FormatException(\"object\", elem == null ? Void.class : elem.getClass());\n          }\n          set.add(parseImport(importObj));\n        }\n        ret.put(key, set);\n      } catch (URISyntaxException e) {\n        throw new MappingException(entry.getKey(), e);\n      }\n    }\n    return ret;\n  }\n\n  private static ImportGraph.Import parseImport(Json.JsObject jsObject) throws JsonParseException {\n    var uri = jsObject.getURI(\"uri\");\n    return new Import(uri);\n  }\n\n  private static Map<URI, URI> parseResolvedImports(Json.JsObject jsObject)\n      throws JsonParseException {","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ImportGraph.java#L58-L94","documentation":"Thrown by ImportGraph.parseImports when decoding the imports section of a serialized (JavaScript-shape) import graph: each entry must be a JsArray of JsObject elements. This FormatException means an element of the array was not a JS object (or was null), so an Import cannot be parsed from it.","triggerScenarios":"Calling imports() on an ImportGraph whose underlying JSON has an imports array containing a null or non-object element (e.g. a string, number, or boolean instead of an object with uri/relation fields).","commonSituations":"Hand-edited or tool-generated import-graph JSON, output from an older/newer Pkl version with a changed schema, or a build cache corrupted or truncated mid-write.","solutions":["Inspect the imports array in the import graph JSON and fix or remove the malformed (null/non-object) element","Regenerate the import graph / clear the build cache so a fresh, valid graph is produced","Check the Pkl version consistency between tools that write and read the graph"],"exampleFix":"// before: imports: [\"module:/a.pkl\"]\n// after:  imports: [{\"uri\": \"module:/a.pkl\"}]","handlingStrategy":"validation","validationCode":"for (var i = 0; i < importsJson.length(); i++) {\n  if (importsJson.get(i) == null || !(importsJson.get(i) instanceof JsObject)) {\n    throw new IllegalArgumentException(\"imports[\" + i + \"] must be an object\");\n  }\n}","typeGuard":"if (!(value instanceof JsArray array)) throw new FormatException(\"array\", value.getClass());\nfor (var elem : array) {\n  if (!(elem instanceof JsObject obj)) throw new FormatException(\"object\", elem.getClass());\n}","tryCatchPattern":"try {\n  graph.imports();\n} catch (FormatException e) {\n  // e shows expected type vs actual type; inspect and repair the import graph JSON\n  LOG.error(\"Malformed import graph: {}\", e.getMessage());\n}","preventionTips":["Never hand-edit import graph JSON; regenerate it via Pkl tooling","Validate cached graph files against the schema after Pkl version upgrades","Checksum/verify cache files to detect truncation or corruption"],"tags":["java","pkl","deserialization","format"],"backgroundTag":"invalid-argument-format","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}