{"record":{"id":"f658ed1a22792460","repo":"apple/pkl","slug":"invalidmoduleuri","errorCode":"invalidModuleUri","errorMessage":"invalidModuleUri","messagePattern":"invalidModuleUri","errorType":"error_code","errorClass":"PklException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/project/ProjectPackager.java","lineNumber":444,"sourceCode":"   *\n   * <p>Note that these might be glob expressions, so these paths might not actually exist. For\n   * example, an import might look like {@code \"foo/*.pkl\"}, which would resolve as path {@code\n   * `/some/dir/foo/*.pkl`}, which is not a real file. This is just a sanity check to ensure that\n   * the paths can reasonably resolve to a location within the package directory.\n   */\n  public void validateImportsAndReads(Project project, Path pklModulePath) {\n    var imports = getImportsAndReads(pklModulePath);\n    for (var importContext : imports) {\n      var importStr = importContext.stringValue();\n      var sourceSection = importContext.sourceSection();\n      if (isAbsoluteImport(importStr)) {\n        continue;\n      }\n      URI importUri;\n      try {\n        importUri = IoUtils.toUri(importStr);\n      } catch (URISyntaxException e) {\n        throw new VmExceptionBuilder()\n            .evalError(\"invalidModuleUri\", importStr)\n            .withSourceSection(sourceSection)\n            .build()\n            .toPklException(stackFrameTransformer, color);\n      }\n      if (importStr.startsWith(\"/\") && !project.getProjectDir().toString().equals(\"/\")) {\n        throw new VmExceptionBuilder()\n            .evalError(\"invalidRelativeProjectImport\", importStr)\n            .withSourceSection(sourceSection)\n            .build()\n            .toPklException(stackFrameTransformer, color);\n      }\n      var currentPath = pklModulePath.getParent();\n      assert currentPath != null;\n      var importPath = importUri.getPath().split(\"/\");\n      // It's not good enough to just check the normalized path to see whether it exists within the\n      // root dir.\n      // It's possible that the import path resolves to a path outside the project dir,","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/project/ProjectPackager.java#L426-L462","documentation":"Raised as an eval error when an import string inside a module being validated cannot be parsed as a URI (IoUtils.toUri throws URISyntaxException). The error is attached to the import's source section so it points at the offending import statement.","triggerScenarios":"validateImportsAndReads (via validatePklImportsAndReads during packaging) encounters an import string containing characters illegal in a URI, such as spaces or unencoded special characters.","commonSituations":"Import paths with spaces like import \"my module/foo.pkl\"; stray backslashes on Windows-style paths; unencoded `#` or `%` in filenames.","solutions":["Fix the import string in the .pkl source to be a valid URI (percent-encode or remove illegal characters)","Use forward slashes and no spaces in file names referenced by imports","Quote/escape special characters in the path"],"exampleFix":"// before\nimport \"my module/foo.pkl\"\n// after\nimport \"my_module/foo.pkl\"","handlingStrategy":"validation","validationCode":"// pre-validate import strings are valid URIs\ntry { new java.net.URI(importStr); } catch (URISyntaxException e) { /* fix import before packaging */ }","typeGuard":null,"tryCatchPattern":"try { validatePklImportsAndReads(project, module, ...) } catch (PklException e) { if (e.message.contains(\"invalidModuleUri\")) reportImportUriError(e) else throw e }","preventionTips":["Avoid spaces and special characters in filenames referenced by imports","Use forward slashes and relative paths in imports","Lint import statements in CI with a URI-validity check"],"tags":["uri","import","validation"],"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"}