{"record":{"id":"2482001bd9d4d721","repo":"apple/pkl","slug":"expected-s-structure-to-have-at-least-d-slots-f","errorCode":null,"errorMessage":"Expected %s structure to have at least %d slots, found %d","messagePattern":"Expected (.+?) structure to have at least (.+?) slots, found (.+?)","errorType":"validation","errorClass":"DecodeException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/util/pklbinary/AbstractPklBinaryDecoder.java","lineNumber":86,"sourceCode":"        return doDecode();\n      } catch (MessageInsufficientBufferException e) {\n        throw new DecodeException(\"Unexpected EOF\", e);\n      }\n    } catch (IOException e) {\n      throw doIOFail(e);\n    } catch (MessagePackException | DecodeException e) {\n      var path = new ArrayList<String>(currPath.size());\n      for (var iter = currPath.descendingIterator(); iter.hasNext(); ) {\n        path.add(iter.next().toString());\n      }\n      Collections.reverse(path);\n      throw doFail(e, unpacker.getTotalReadBytes(), path);\n    }\n  }\n\n  private void assertLength(PklBinaryCode type, int len, int expected) {\n    if (len < expected) {\n      throw new DecodeException(\n          \"Expected %s structure to have at least %d slots, found %d\", type, expected + 1, len);\n    }\n  }\n\n  protected record DecodedObjectMember(PklBinaryCode type, Object key, Object value) {}\n\n  protected abstract RuntimeException doFail(Exception cause, long offset, List<String> path);\n\n  protected abstract RuntimeException doIOFail(IOException cause);\n\n  protected abstract Object doDecodeNull();\n\n  protected abstract Object doDecodeObject(\n      String className, URI moduleUri, DecodeIterator<DecodedObjectMember> iter);\n\n  protected abstract Object doDecodeMap(MapDecodeIterator iter);\n\n  protected abstract Object doDecodeMapping(MapDecodeIterator iter);","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/util/pklbinary/AbstractPklBinaryDecoder.java#L68-L104","documentation":"DecodeException thrown by assertLength when a msgpack array header declares fewer slots than a Pkl binary structure requires. Every PklBinaryCode-typed structure (object, map, mapping, list, listing, set) encodes a fixed number of leading slots (code, count, members) that must be present. Note the message reports expected+1 as the minimum.","triggerScenarios":"A non-primitive array whose header length is less than the minimum required for its PklBinaryCode type; produced when a writer emits a header claiming fewer elements than the type's fixed prologue needs (e.g. a 0- or 1-element array claiming to be an OBJECT).","commonSituations":"Hand-crafted or corrupted Pkl binary payloads; a producer bug emitting wrong array headers; partial deserialization where only part of an object array was written.","solutions":["Regenerate the binary payload with a valid Pkl writer; the array header slot count is wrong","Verify the bytes are genuine Pkl binary output, not msgpack from another tool","Check producer/consumer Pkl version compatibility for the binary encoding","If writing a custom AbstractPklBinaryDecoder subclass, confirm decodeObject/decodeMap/etc. read the correct slot layout"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Producers: ensure every non-primitive array header length covers the fixed prologue slots\n// e.g. an OBJECT needs: code + memberCount + members*\nassert arrayLen >= minSlotsFor(code);","typeGuard":null,"tryCatchPattern":"try {\n  Object v = decoder.decode(bytes);\n} catch (DecodeException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"at least\")) {\n    // treat payload as invalid; re-encode from source\n  } else throw e;\n}","preventionTips":["Use the official Pkl encoder; do not hand-assemble msgpack arrays","Keep the number of declared array slots consistent with the structure's members","Validate fixtures against the Pkl binary schema before shipping them","Add round-trip tests: encode with writer, decode with reader"],"tags":["msgpack","decoding","pkl-binary","malformed-input"],"backgroundTag":"schema-validation-failed","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"}