{"record":{"id":"814e18770cddfd42","repo":"apple/pkl","slug":"unsupportedresourcetype","errorCode":"unsupportedResourceType","errorMessage":"unsupportedResourceType","messagePattern":"unsupportedResourceType","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/runtime/ResourceManager.java","lineNumber":129,"sourceCode":"            }\n          }\n          if (reader == null) {\n            throw new VmExceptionBuilder()\n                .withOptionalLocation(readNode)\n                .evalError(\"noResourceReaderRegistered\", uri.getScheme())\n                .build();\n          }\n          var resource = doRead(reader, uri, readNode);\n          if (resource.isEmpty()) return resource;\n\n          var res = resource.get();\n          if (res instanceof String) return resource;\n\n          if (res instanceof Resource r) {\n            return Optional.of(resourceFactory.create(r));\n          }\n\n          throw new VmExceptionBuilder()\n              .evalError(\"unsupportedResourceType\", reader.getClass().getName(), res.getClass())\n              .withOptionalLocation(readNode)\n              .build();\n        });\n  }\n\n  /**\n   * Returns a {@link ResourceReader} registered to read the resource at {@code baseUri}, or {@code\n   * null} if there is none.\n   */\n  public @Nullable ResourceReader getResourceReader(URI baseUri) {\n    return resourceReaders.get(baseUri.getScheme());\n  }\n}\n","sourceCodeStart":111,"sourceCodeEnd":144,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/runtime/ResourceManager.java#L111-L144","documentation":"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.","triggerScenarios":"read() path where doRead() returns a value that is neither String nor Resource — i.e. a custom ResourceReader implementation returned an unexpected object type.","commonSituations":"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.","solutions":["Fix the custom ResourceReader to return String or a Resource (e.g. ByteArrayResource/UrlResource) from read().","Upgrade or replace the third-party reader so it matches your Pkl runtime API.","Inspect the error message: it names the reader class and the actual returned class."],"exampleFix":"// before\npublic Optional<Object> read(URI uri) { return Optional.of(Files.readAllBytes(path)); }\n// after\npublic Optional<Object> read(URI uri) { return Optional.of(new ByteArrayResource(Files.readAllBytes(path), uri)); }","handlingStrategy":"validation","validationCode":"Object res = reader.read(uri).orElse(null);\nif (!(res instanceof String) && !(res instanceof org.pkl.core.Resource)) { /* reader is broken — fix it */ }","typeGuard":"static boolean isValidReaderResult(Object r) { return r instanceof String || r instanceof org.pkl.core.Resource; }","tryCatchPattern":"catch (VmException e) { if (\"unsupportedResourceType\".equals(e.getCode())) { /* report the buggy reader class named in the message */ } }","preventionTips":["Custom readers must return String or a Resource implementation only.","Unit-test custom ResourceReaders against the Pkl runtime before deployment."],"tags":["resource-read","custom-reader","type-mismatch"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}