{"record":{"id":"d8703d33ce4699a1","repo":"apple/pkl","slug":"invalidmoduleuri-d8703d","errorCode":"invalidModuleUri","errorMessage":"invalidModuleUri","messagePattern":"invalidModuleUri","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/runtime/CommandSpecParser.java","lineNumber":1169,"sourceCode":"\n  private Object handleImport(VmTyped mport, URI workingDirUri) {\n    var moduleName = (String) VmUtils.readMember(mport, Identifier.URI);\n    String uriString;\n    // Ported from org.pkl.cli.commons.cli.commands.BaseOptions:\n    try {\n      // Can't just use URI constructor, because URI(null, null, \"C:/foo/bar\", null) turns\n      // into `URI(\"C\", null, \"/foo/bar\", null)`.\n      @SuppressWarnings(\"DuplicateExpressions\")\n      var uri =\n          IoUtils.isUriLike(moduleName)\n              ? new URI(moduleName)\n              : IoUtils.isWindows() && IoUtils.isWindowsAbsolutePath(moduleName)\n                  ? Path.of(moduleName).toUri()\n                  : new URI(null, null, IoUtils.toNormalizedPathString(Path.of(moduleName)), null);\n      uriString =\n          uri.isAbsolute() ? uri.toString() : IoUtils.resolve(workingDirUri, uri).toString();\n    } catch (URISyntaxException e) {\n      throw exceptionBuilder()\n          .evalError(\"invalidModuleUri\", moduleName)\n          .withHint(e.getReason())\n          .build();\n    }\n\n    var isGlob = (Boolean) VmUtils.readMember(mport, Identifier.GLOB);\n    var importUri = URI.create(uriString);\n    var language = VmLanguage.get(null);\n\n    // non-glob\n    if (!isGlob) {\n      var moduleKey = moduleResolver.resolve(importUri);\n      return language.loadModule(moduleKey);\n    }\n\n    // glob\n    var globModuleKey = moduleResolver.resolve(importUri);\n","sourceCodeStart":1151,"sourceCodeEnd":1187,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/runtime/CommandSpecParser.java#L1151-L1187","documentation":"Thrown when the `uri` string of an import (e.g. an entry in the `imports` mapping of a pkl test or command context) cannot be parsed as a URI or path. Java's URISyntaxException is caught in handleImport and re-raised as invalidModuleUri with the offending string and a hint describing the syntax problem.","triggerScenarios":"An import entry value containing characters illegal in a URI (spaces, stray `%` not followed by hex digits, unmatched brackets, illegal control characters), parsed via `new URI(...)` or Path.toUri in handleImport.","commonSituations":"File paths with unencoded spaces or `%` characters (e.g. \"my dir/file%.pkl\"); pasted URLs with typos; Windows paths with mixed separators entering the wrong branch; interpolating unescaped values into a URI.","solutions":["Percent-encode the URI: replace spaces with %20 and any literal % with %25","Fix the malformed URI syntax flagged by the hint (e.g. stray %, brackets)","Use a plain relative file path instead of a partially-formed URI"],"exampleFix":"// before\n\"my file%.pkl\"\n\n// after\n\"my%20file%25.pkl\"","handlingStrategy":"try-catch","validationCode":"// validate the uri string before placing it in an import entry\nfunction isValidUri(s: String): Boolean {\n  try {\n    new java.net.URI(if (s.contains(\":\")) s else \"file://\" + encodePath(s))\n    true\n  } catch (e: URISyntaxException) { false }\n}","typeGuard":null,"tryCatchPattern":"try {\n  context = parseTestContext(...)\n} catch (EvaluationException e) {\n  if (e.getMessage().startsWith(\"invalidModuleUri\")) {\n    // e has a hint with the URISyntaxException reason; fix the uri string\n  }\n}","preventionTips":["Percent-encode spaces and % characters in file paths used as URIs","Prefer plain relative paths for local files; reserve full URIs for remote schemes","Validate interpolated strings before embedding them in import URIs"],"tags":["pkl","uri","import","syntax"],"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-14T16:17:12.679Z"}