{"record":{"id":"ab0346169edc0621","repo":"apple/pkl","slug":"invaliduri-ab0346","errorCode":"invalidUri","errorMessage":"invalidUri","messagePattern":"invalidUri","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/stdlib/evaluatorsettings/EvaluatorSettingsNodes.java","lineNumber":38,"sourceCode":"import java.net.URI;\nimport java.net.URISyntaxException;\nimport org.pkl.core.runtime.VmTyped;\nimport org.pkl.core.stdlib.ExternalMethod3Node;\nimport org.pkl.core.util.PathResolver;\nimport org.pkl.core.util.PathResolvers;\n\npublic class EvaluatorSettingsNodes {\n\n  public abstract static class resolvePath extends ExternalMethod3Node {\n    @TruffleBoundary\n    private URI toUri(String baseUri) {\n      try {\n        var uri = new URI(baseUri);\n        // guaranteed by Pkl\n        assert uri.getScheme().equals(\"file\");\n        return uri;\n      } catch (URISyntaxException e) {\n        throw exceptionBuilder().evalError(\"invalidUri\", baseUri).build();\n      }\n    }\n\n    private PathResolver getPathResolver(boolean forWindows) {\n      return forWindows ? PathResolvers.forWindows() : PathResolvers.forPosix();\n    }\n\n    @TruffleBoundary\n    @Specialization\n    protected String eval(VmTyped ignored, String uriStr, String path, boolean forWindows) {\n      var uri = toUri(uriStr);\n      var baseUri = uri.resolve(\".\");\n      var resolver = getPathResolver(forWindows);\n      return resolver.resolvePath(baseUri, path);\n    }\n  }\n}\n","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/stdlib/evaluatorsettings/EvaluatorSettingsNodes.java#L20-L56","documentation":"Thrown when converting the evaluator's baseUri setting into a java.net.URI fails because the value is not a syntactically valid URI. Although Pkl guarantees a file scheme internally, a malformed URI string supplied via EvaluatorSettings triggers this eval error with the offending URI attached.","triggerScenarios":"Setting `baseUri` in EvaluatorSettings to a string that violates URI syntax (illegal characters, unescaped spaces, missing scheme, unbalanced brackets) — e.g. baseUri = \"file://C:\\\\path\" or \"file:/my dir/\".","commonSituations":"Windows-style paths with backslashes or spaces used unescaped; URIs built by naive string concatenation without percent-encoding; environment-specific config with typos.","solutions":["Percent-encode spaces and special characters in the path (e.g. 'my%20dir')","Use forward slashes and a proper file URI form: file:///C:/path/to/dir","Validate the URI with a URI parser before assigning it to baseUri","Construct the URI programmatically from a Path instead of hand-writing the string"],"exampleFix":"// before\nbaseUri = \"file:///my projects/app\"\n// after\nbaseUri = \"file:///my%20projects/app\"","handlingStrategy":"validation","validationCode":"function isSafeFileUri(u: String): Boolean = u.isRegexMatch(/^file:\\/\\/\\/[^\\s<>\"\\\\]+$/, _)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Percent-encode spaces and special characters in paths","Always use the file:/// form with forward slashes","Build baseUri programmatically from a Path rather than string concatenation"],"tags":["uri","config","evaluator-settings"],"backgroundTag":"invalid-url-format","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"}