apple/pkl · error · VmException

ioErrorReadingResource

ioErrorReadingResource

Error message

I/O error reading resource `{0}`.

What it means

Pkl throws this when reading a resource fails with a general IOException that is not a simple FileNotFoundException — the URI resolved but the underlying transport (filesystem, HTTP, package loader) hit an I/O problem. The original exception message is attached as a hint.

Solutions

  1. Read the hint (IOException message) to identify the underlying transport failure.
  2. Check network connectivity, proxy settings, and that the remote host is reachable.
  3. Verify filesystem permissions on the target file.
  4. Ensure the URI points to a file, not a directory, and that any required services are running.

Example fix

// before
x = read("https://internal.corp/api/config")  // blocked by proxy
// after
x = read("https://proxy-adjusted-host/api/config") // or fix proxy env: HTTPS_PROXY
Defensive patterns

Strategy: try-catch

Try / catch

// Host-side (Java) around Pkl evaluation or reader setup:
try {
  result = evaluator.evaluateOutputSource(moduleSource);
} catch (PklException e) {
  if (e.getMessage() != null && e.getMessage().contains("I/O error reading resource")) {
    // log hint, check connectivity/permissions, retry with backoff if transient
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `read()` where the target exists conceptually but I/O fails: network errors during HTTP fetch, permission errors on open, connection reset mid-transfer, directory read attempts.

Common situations: Offline environment or proxy blocking an https resource read; filesystem permissions deny access; remote host unreachable; reading a path that is a directory rather than a file.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/79856ca032e8e5d6. Report an issue: GitHub.

Appendix: source

Thrown at pkl-core/src/main/java/org/pkl/core/ast/expression/unary/AbstractReadNode.java:73

    var resolvedUri = resolveResource(currentModule, resourceUri);
    return context.getResourceManager().read(resolvedUri, readNode).orElse(null);
  }

  private URI resolveResource(ModuleKey moduleKey, String resourceUri) {
    var parsedUri = parseUri(resourceUri);
    var context = VmContext.get(this);
    URI resolvedUri;
    try {
      resolvedUri = IoUtils.resolve(context.getSecurityManager(), moduleKey, parsedUri);
    } catch (FileNotFoundException e) {
      throw exceptionBuilder().evalError("cannotFindResource", resourceUri).build();
    } catch (URISyntaxException e) {
      throw exceptionBuilder()
          .evalError("invalidResourceUri", resourceUri)
          .withHint(e.getReason())
          .build();
    } catch (IOException e) {
      throw exceptionBuilder()
          .evalError("ioErrorReadingResource", resourceUri)
          .withHint(e.getMessage())
          .build();
    } catch (PackageLoadError | SecurityManagerException e) {
      throw exceptionBuilder().withCause(e).build();
    } catch (ExternalReaderProcessException e) {
      throw exceptionBuilder().evalError("externalReaderFailure").withCause(e).build();
    }

    if (!resolvedUri.isAbsolute()) {
      throw exceptionBuilder().evalError("cannotHaveRelativeResource", moduleKey.getUri()).build();
    }
    return resolvedUri;
  }
}

View on GitHub (pinned to f3efcbfc9b)