{"record":{"id":"982b87959d870bad","repo":"apple/pkl","slug":"cannothaverelativeresource","errorCode":"cannotHaveRelativeResource","errorMessage":"Module `{0}` cannot have a relative resource URI.","messagePattern":"Module `(.+?)` cannot have a relative resource URI\\.","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/unary/AbstractReadNode.java","lineNumber":84,"sourceCode":"      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();\n    }\n    return resolvedUri;\n  }\n}\n","sourceCodeStart":66,"sourceCodeEnd":89,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/unary/AbstractReadNode.java#L66-L89","documentation":"Pkl throws this after resolution when the resolved resource URI is not absolute. Resource URIs must resolve to absolute URIs; a relative result means the module's own key cannot serve as a proper resolution base. The module's URI is reported in the message.","triggerScenarios":"Calling `read()` from a module whose key is a relative or scheme-less URI, with a relative resource URI that does not become absolute after resolution.","commonSituations":"Evaluating modules via REPL or API with synthetic/non-standard module keys; reading resources from a module that was loaded as raw text with no proper base URI.","solutions":["Use an absolute resource URI (with scheme) in the read() call.","Load the module through a proper resolvable source (file path or URL) so its module key is absolute.","Fix how the module is evaluated programmatically — pass a resolved ModuleSource/URI rather than raw text.","Check the reported module URI to see why the base cannot produce an absolute result."],"exampleFix":"// before\nread(\"config.json\")  // module has no absolute base\n// after\nread(\"file:///path/to/project/config.json\")","handlingStrategy":"validation","validationCode":"// Host side: ensure modules are loaded from resolvable sources\n// ModuleSource path/url must be absolute: Path.of(p).toAbsolutePath() / new URI(...).resolve(...)  != null && uri.isAbsolute()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never evaluate raw text modules that also perform read(); give them a real base URI.","Use absolute resource URIs when the module origin is uncertain.","Verify module keys are absolute when integrating Pkl via the Java API or REPL."],"tags":["uri","resource","module","pkl"],"backgroundTag":"invalid-url","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"}