apple/pkl · error · VmException

unsupportedResourceType

unsupportedResourceType

Error message

unsupportedResourceType

What it means

After a ResourceReader returns a value, ResourceManager.read() expects it to be a String or a Resource. Any other type indicates a broken/buggy reader, and Pkl throws eval error 'unsupportedResourceType' naming the reader class and the offending value's class.

Solutions

  1. Fix the custom ResourceReader to return String or a Resource (e.g. ByteArrayResource/UrlResource) from read().
  2. Upgrade or replace the third-party reader so it matches your Pkl runtime API.
  3. Inspect the error message: it names the reader class and the actual returned class.

Example fix

// before
public Optional<Object> read(URI uri) { return Optional.of(Files.readAllBytes(path)); }
// after
public Optional<Object> read(URI uri) { return Optional.of(new ByteArrayResource(Files.readAllBytes(path), uri)); }
Defensive patterns

Strategy: validation

Validate before calling

Object res = reader.read(uri).orElse(null);
if (!(res instanceof String) && !(res instanceof org.pkl.core.Resource)) { /* reader is broken — fix it */ }

Type guard

static boolean isValidReaderResult(Object r) { return r instanceof String || r instanceof org.pkl.core.Resource; }

Try / catch

catch (VmException e) { if ("unsupportedResourceType".equals(e.getCode())) { /* report the buggy reader class named in the message */ } }

Prevention

When it happens

Trigger: read() path where doRead() returns a value that is neither String nor Resource — i.e. a custom ResourceReader implementation returned an unexpected object type.

Common situations: Writing a custom ResourceReader whose read() returns e.g. a byte[]/Map instead of String or a Resource; a reader from a third-party library incompatible with the Pkl runtime version.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at pkl-core/src/main/java/org/pkl/core/runtime/ResourceManager.java:129

            }
          }
          if (reader == null) {
            throw new VmExceptionBuilder()
                .withOptionalLocation(readNode)
                .evalError("noResourceReaderRegistered", uri.getScheme())
                .build();
          }
          var resource = doRead(reader, uri, readNode);
          if (resource.isEmpty()) return resource;

          var res = resource.get();
          if (res instanceof String) return resource;

          if (res instanceof Resource r) {
            return Optional.of(resourceFactory.create(r));
          }

          throw new VmExceptionBuilder()
              .evalError("unsupportedResourceType", reader.getClass().getName(), res.getClass())
              .withOptionalLocation(readNode)
              .build();
        });
  }

  /**
   * Returns a {@link ResourceReader} registered to read the resource at {@code baseUri}, or {@code
   * null} if there is none.
   */
  public @Nullable ResourceReader getResourceReader(URI baseUri) {
    return resourceReaders.get(baseUri.getScheme());
  }
}

View on GitHub (pinned to f3efcbfc9b)