{"record":{"id":"d3650b7b13a5c767","repo":"apple/pkl","slug":"cannotfindresource","errorCode":"cannotFindResource","errorMessage":"Cannot find resource `{0}`.","messagePattern":"Cannot find resource `(.+?)`\\.","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/unary/AbstractReadNode.java","lineNumber":66,"sourceCode":"          .withHint(e.getReason())\n          .build();\n    }\n  }\n\n  @TruffleBoundary\n  protected final @Nullable Object doRead(String resourceUri, VmContext context, Node readNode) {\n    var resolvedUri = resolveResource(currentModule, resourceUri);\n    return context.getResourceManager().read(resolvedUri, readNode).orElse(null);\n  }\n\n  private URI resolveResource(ModuleKey moduleKey, String resourceUri) {\n    var parsedUri = parseUri(resourceUri);\n    var context = VmContext.get(this);\n    URI resolvedUri;\n    try {\n      resolvedUri = IoUtils.resolve(context.getSecurityManager(), moduleKey, parsedUri);\n    } catch (FileNotFoundException e) {\n      throw exceptionBuilder().evalError(\"cannotFindResource\", resourceUri).build();\n    } catch (URISyntaxException e) {\n      throw exceptionBuilder()\n          .evalError(\"invalidResourceUri\", resourceUri)\n          .withHint(e.getReason())\n          .build();\n    } catch (IOException e) {\n      throw exceptionBuilder()\n          .evalError(\"ioErrorReadingResource\", resourceUri)\n          .withHint(e.getMessage())\n          .build();\n    } catch (PackageLoadError | SecurityManagerException e) {\n      throw exceptionBuilder().withCause(e).build();\n    } catch (ExternalReaderProcessException e) {\n      throw exceptionBuilder().evalError(\"externalReaderFailure\").withCause(e).build();\n    }\n\n    if (!resolvedUri.isAbsolute()) {\n      throw exceptionBuilder().evalError(\"cannotHaveRelativeResource\", moduleKey.getUri()).build();","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/unary/AbstractReadNode.java#L48-L84","documentation":"Pkl throws this when a resource URI parsed successfully but IoUtils.resolve, which resolves the URI relative to the current module key through the security manager, reports that the target resource does not exist (FileNotFoundException). The resource simply cannot be located at the resolved location.","triggerScenarios":"Calling `read()` with a URI whose resolved target file/endpoint does not exist: wrong relative path from the module, misspelled filename, or a deleted/moved file.","commonSituations":"Typo in a file path relative to the module; resource lives in a different directory than assumed; CI environment lacks the file; path casing differs on case-sensitive filesystems.","solutions":["Verify the file/resource exists at the resolved location; print the URI to confirm where it resolves relative to the module.","Fix relative paths — remember they resolve against the module's location, not the working directory.","Check filename spelling and case, especially on Linux CI.","If the resource comes from a package, ensure the package is loaded and actually contains the resource."],"exampleFix":"// before\nread(\"confg.json\")\n// after\nread(\"config.json\")","handlingStrategy":"validation","validationCode":"// Before evaluating, check the resource exists relative to the module file\n// host side (Java/Kotlin):\n//   java.nio.file.Files.exists(Path.of(moduleDir, resourcePath))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember relative resources resolve against the module file, not the CWD.","Check spelling and casing of filenames, especially on Linux CI.","Commit all resources the evaluation depends on; avoid machine-local absolute paths."],"tags":["resource","file-not-found","path","pkl"],"backgroundTag":"file-not-found","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}