{"record":{"id":"a53a1fc47001d1be","repo":"apple/pkl","slug":"cannot-decode-function-value","errorCode":null,"errorMessage":"Cannot decode Function value","messagePattern":"Cannot decode Function value","errorType":"exception","errorClass":"DecodeException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/util/pklbinary/AbstractPklBinaryDecoder.java","lineNumber":127,"sourceCode":"\n  protected abstract Object doDecodeSet(CollectionDecodeIterator iter);\n\n  protected abstract Object doDecodeDuration(double value, DurationUnit unit);\n\n  protected abstract Object doDecodeDataSize(double value, DataSizeUnit unit);\n\n  protected abstract Object doDecodePair(Object first, Object second);\n\n  protected abstract Object doDecodeIntSeq(long start, long end, long step);\n\n  protected abstract Object doDecodeRegex(Pattern pattern);\n\n  protected abstract Object doDecodeClass(String qualifiedName, URI moduleUri);\n\n  protected abstract Object doDecodeTypeAlias(String qualifiedName, URI moduleUri);\n\n  protected Object doDecodeFunction() {\n    throw new DecodeException(\"Cannot decode Function value\");\n  }\n\n  protected abstract Object doDecodeBytes(byte[] bytes);\n\n  private Object doDecode() throws IOException {\n    if (!unpacker.hasNext()) {\n      throw new DecodeException(\"Unexpected EOF\");\n    }\n\n    return switch (unpacker.getNextFormat().getValueType()) {\n      // primitives\n      case NIL -> {\n        unpacker.unpackNil();\n        yield doDecodeNull();\n      }\n      case STRING -> unpacker.unpackString();\n      case INTEGER -> unpacker.unpackLong();\n      case BOOLEAN -> unpacker.unpackBoolean();","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/util/pklbinary/AbstractPklBinaryDecoder.java#L109-L145","documentation":"DecodeException thrown by the default doDecodeFunction() implementation, which is deliberately unsupported. Pkl binary encoding can tag a value as FUNCTION, but this decoder cannot reconstruct a function value, so any FUNCTION-tagged member aborts decoding. Subclasses may override doDecodeFunction, but the base class throws by default.","triggerScenarios":"Decoding a Pkl value that contains a function (e.g. an object property whose value is a function) via a decoder that does not implement doDecodeFunction — such as decoding evaluator output that includes a function-typed property.","commonSituations":"Externalizing module values that reference Pkl functions; passing evaluator-rendered output containing function members through the pkl-binary channel; cache tools that snapshot values which happen to include lambdas.","solutions":["Remove function-valued members from the data being encoded (functions cannot cross the binary boundary)","Override doDecodeFunction() in your AbstractPklBinaryDecoder subclass to return a placeholder or handle functions explicitly","Convert the function value to a string/URI representation before encoding","Use a Pkl version/decoder that supports function round-tripping if one is available"],"exampleFix":"// before\n// base class: throws\n// after (subclass)\n@Override\nprotected Object doDecodeFunction() {\n  return \"<function>\"; // or throw a domain-specific error\n}","handlingStrategy":"type-guard","validationCode":"// Before exporting a Pkl value, ensure it contains no function-valued members\n// e.g. in Pkl: check properties are data (String/Int/List/Listing/Object), not (x) -> ...","typeGuard":null,"tryCatchPattern":"try {\n  Object v = decoder.decode(bytes);\n} catch (DecodeException e) {\n  if (\"Cannot decode Function value\".equals(e.getMessage())) {\n    // re-request data without function members, or override doDecodeFunction\n  } else throw e;\n}","preventionTips":["Never encode function values across the Pkl binary boundary; encode references (names/URIs) instead","Audit modules for function-typed properties before externalizing values","Override doDecodeFunction in custom decoders if functions must be tolerated"],"tags":["pkl-binary","decoding","unsupported-operation","function-value"],"backgroundTag":"unsupported-operation","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"}