{"record":{"id":"1b687825241d33cf","repo":"apple/pkl","slug":"ioerrorloadingmodule-1b6878","errorCode":"ioErrorLoadingModule","errorMessage":"ioErrorLoadingModule","messagePattern":"ioErrorLoadingModule","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/runtime/VmUtils.java","lineNumber":613,"sourceCode":"\n  @TruffleBoundary\n  public static String builderToString(StringBuilder builder) {\n    return builder.toString();\n  }\n\n  public static void checkPositive(long n) {\n    if (n < 0) {\n      CompilerDirectives.transferToInterpreter();\n      throw new VmExceptionBuilder().evalError(\"expectedPositiveNumber\", n).build();\n    }\n  }\n\n  public static Source loadSource(ResolvedModuleKey resolvedKey) {\n    try {\n      var text = resolvedKey.loadSource();\n      return createSource(resolvedKey.getOriginal(), text);\n    } catch (IOException e) {\n      throw new VmExceptionBuilder()\n          .evalError(\"ioErrorLoadingModule\", resolvedKey.getOriginal().getUri())\n          .withCause(e)\n          .build();\n    }\n  }\n\n  public static Source createSource(ModuleKey moduleKey, String text) {\n    return Source.newBuilder(\"pkl\", text, moduleKey.getUri().toString())\n        .mimeType(VmLanguage.MIME_TYPE)\n        .uri(moduleKey.getUri())\n        .cached(false)\n        .build();\n  }\n\n  public static VmException toVmException(\n      ParserError e, String text, URI moduleUri, String moduleName) {\n    var source =\n        Source.newBuilder(\"pkl\", text, moduleName)","sourceCodeStart":595,"sourceCodeEnd":631,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/runtime/VmUtils.java#L595-L631","documentation":"`VmUtils.loadSource` wraps IOExceptions from `ResolvedModuleKey.loadSource()` into an ioErrorLoadingModule evalError carrying the module URI. Pkl throws this when a module cannot be physically read during loading (network, filesystem, or resolver failure).","triggerScenarios":"Importing/evaluating a module whose resolved URI cannot be loaded: file deleted or unreadable, remote fetch failing (network down, HTTP error on package/module fetch), bad permissions.","commonSituations":"Missing project files after a fresh clone, mistyped paths in imports, offline environments trying to fetch package modules, filesystem permission changes in CI containers.","solutions":["Check the module URI/path is correct and the file exists.","Verify filesystem read permissions for the process.","For remote modules, check network connectivity and registry/package availability.","Ensure all dependencies (Pkl packages, project files) are vendored or cached before running in CI/offline."],"exampleFix":"// before\nimport \"config/prod_config.pkl\"\n// after (file was renamed)\nimport \"config/prod.config.pkl\"","handlingStrategy":"retry","validationCode":"// check the module file exists and is readable before import/eval\nfs.accessSync(modulePath, fs.constants.R_OK)","typeGuard":"function moduleIsLoadable(uri) { try { fs.statSync(toPath(uri)); return true; } catch { return false; } }","tryCatchPattern":"try { loadSource(resolvedKey) } catch (e) { if (e.message.includes('ioErrorLoadingModule')) { /* check path/network, then retry */ } throw e; }","preventionTips":["Vendor or pre-fetch package modules for offline/CI runs","Verify paths relative to the project root","Check file permissions in containers"],"tags":["pkl","io","module-loading","filesystem"],"backgroundTag":"file-read-failed","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"}