apple/pkl · error · FormatException
FormatException("resolvedDependencies", "object"…
Error message
FormatException("resolvedDependencies", "object", object.getClass()) What it means
parseResolvedDependencies expects the 'resolvedDependencies' member of a ProjectDeps file to be a JSON object (JsObject). If it is any other JSON type (array, string, number), a FormatException names the field, the expected type 'object', and the actual class.
Solutions
- Restore resolvedDependencies to an object mapping package URIs to dependency objects
- Regenerate the deps file via the Pkl project tooling instead of editing by hand
- Validate the JSON structure before parsing
Example fix
// before
"resolvedDependencies": []
// after
"resolvedDependencies": { "package://example.com/foo@1": { "type": "remote", "uri": "...", "checksums": {...} } } Defensive patterns
Strategy: type-guard
Validate before calling
Object rd = Json.parseObject(input).get("resolvedDependencies");
if (!(rd instanceof Map)) throw new IllegalArgumentException("resolvedDependencies must be an object"); Type guard
boolean isObject(Object o) { return o instanceof Map<?, ?>; } Try / catch
try { ProjectDeps.parse(input); } catch (FormatException e) { log.error("deps file malformed: {}", e.getMessage()); } Prevention
- Never hand-edit the deps file structure
- Regenerate via the Pkl CLI after conflicts or corruption
- Validate JSON structure in CI before consuming
When it happens
Trigger: ProjectDeps.parse on input whose resolvedDependencies value is not an object — e.g. hand-edited to an array or null.
Common situations: Manual edits to the deps file; a different tool or script rewriting the file with the wrong structure; truncation or merge conflicts corrupting the JSON shape.
Related errors
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/346dc8035aae98a0.
Report an issue: GitHub.
Appendix: source
Thrown at pkl-core/src/main/java/org/pkl/core/project/ProjectDeps.java:104
var input = Files.readString(path);
return parse(input);
}
public static ProjectDeps parse(String input) throws JsonParseException {
var parsed = Json.parseObject(input);
var schemaVersion = parsed.getInt("schemaVersion");
if (!supportedSchemaVersions.contains(schemaVersion)) {
throw new PackageLoadError("unsupportedProjectDepsVersion", schemaVersion);
}
var resolvedDependencies =
parsed.get("resolvedDependencies", ProjectDeps::parseResolvedDependencies);
return new ProjectDeps(resolvedDependencies);
}
private static EconomicMap<CanonicalPackageUri, Dependency> parseResolvedDependencies(
Object object) throws JsonParseException, URISyntaxException {
if (!(object instanceof JsObject jsObj)) {
throw new FormatException("resolvedDependencies", "object", object.getClass());
}
var ret = EconomicMaps.<CanonicalPackageUri, Dependency>create(jsObj.size());
for (var entry : jsObj.entrySet()) {
Dependency resolvedDependency = parseResolvedDependency(entry);
var canonicalPackageUri = CanonicalPackageUri.of(entry.getKey());
ret.put(canonicalPackageUri, resolvedDependency);
}
return ret;
}
private static Dependency parseResolvedDependency(Entry<String, Object> entry)
throws JsonParseException {
var input = entry.getValue();
if (!(input instanceof JsObject obj)) {
throw new VmExceptionBuilder().evalError("invalid object").build();
}
var type = obj.getString("type");
var uri = obj.get("uri", PackageUtils::parsePackageUriWithoutChecksums);View on GitHub (pinned to f3efcbfc9b)