apple/pkl · error
cannotFindResource
cannotFindResource
Error message
cannotFindResource
What it means
Thrown while reading one element of a globbed resource (`read(...).text` etc.) when the resource manager cannot find a file for the matched URI. The glob matched the path, but the actual resource disappeared or is unreadable, so the lookup returns empty.
Solutions
- Confirm the file at the reported URI still exists and is inside the module path/allowed roots.
- Re-run so the glob re-resolves against the current directory contents.
- Check pkl.modulePath and security manager include/exclude rules for the resource location.
- If resources are generated, ensure generation completes before evaluation.
Defensive patterns
Strategy: fallback
Validate before calling
// before evaluating, ensure matched files exist: // ls <dir covered by glob>
Try / catch
try {
processGlobbedResource(path)
} catch (e) {
if (e.code === 'cannotFindResource') skipOrRegenerate(e.data.resourceUri)
else throw e
} Prevention
- Ensure globbed files are not deleted between listing and read
- Keep all globbed resources inside the module path
- Generate resources before running evaluation
- Re-resolve globs after filesystem changes
When it happens
Trigger: Globbing resources (e.g. `read("*.txt")` in a `read` glob context) where a matched file is deleted, moved, or excluded by a module path/security rule between match and read, making ResourceManager.read return empty.
Common situations: Files removed after glob listing, module-path changes excluding matched files, caching of glob results while files change on disk, typos in resource paths matched only loosely.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/87fe4cb05dc7800f.
Report an issue: GitHub.
Appendix: source
Thrown at pkl-core/src/main/java/org/pkl/core/ast/expression/unary/ReadGlobMemberBodyNode.java:50
}
@Override
public Object executeGeneric(VirtualFrame frame) {
var mapping = VmUtils.getOwner(frame);
var path = (String) VmUtils.getMemberKey(frame);
return readResource(mapping, path);
}
private Object readResource(VmObjectLike mapping, String path) {
@SuppressWarnings("unchecked")
var globElements = (Map<String, ResolvedGlobElement>) mapping.getExtraStorage();
var globElement = VmUtils.getMapValue(globElements, path);
assert globElement != null;
var resourceUri = globElement.uri();
var resource = VmContext.get(this).getResourceManager().read(resourceUri, this).orElse(null);
if (resource == null) {
CompilerDirectives.transferToInterpreter();
throw exceptionBuilder().evalError("cannotFindResource", resourceUri).build();
}
return resource;
}
}
View on GitHub (pinned to f3efcbfc9b)