{"record":{"id":"0495f349703a3e8f","repo":"apple/pkl","slug":"malformedmessagebody","errorCode":"malformedMessageBody","errorMessage":"malformedMessageBody","messagePattern":"malformedMessageBody","errorType":"error_code","errorClass":"DecodeException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/messaging/AbstractMessagePackDecoder.java","lineNumber":85,"sourceCode":"    Type msgType;\n    try {\n      msgType = Type.fromInt(code);\n    } catch (IllegalArgumentException e) {\n      throw new DecodeException(\n          ErrorMessages.create(\"malformedMessageHeaderUnrecognizedCode\", Integer.toHexString(code)),\n          e);\n    }\n\n    try {\n      var map = unpacker.unpackValue().asMapValue().map();\n      var decoded = decodeMessage(msgType, map);\n      if (decoded != null) {\n        return decoded;\n      }\n      throw new DecodeException(\n          ErrorMessages.create(\"unhandledMessageCode\", Integer.toHexString(code)));\n    } catch (MessageTypeException | URISyntaxException e) {\n      throw new DecodeException(ErrorMessages.create(\"malformedMessageBody\", code), e);\n    }\n  }\n\n  protected static @Nullable Value getNullable(Map<Value, Value> map, String key) {\n    return map.get(new ImmutableStringValueImpl(key));\n  }\n\n  protected static Value get(Map<Value, Value> map, String key) throws DecodeException {\n    var value = map.get(new ImmutableStringValueImpl(key));\n    if (value == null) {\n      throw new DecodeException(ErrorMessages.create(\"missingMessageParameter\", key));\n    }\n    return value;\n  }\n\n  protected static String unpackString(Map<Value, Value> map, String key) throws DecodeException {\n    return get(map, key).asStringValue().asString();\n  }","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/messaging/AbstractMessagePackDecoder.java#L67-L103","documentation":"While decoding a message body map, a MessageTypeException (wrong MessagePack type for a field) or URISyntaxException (malformed URI field) occurred; the decoder wraps it as DecodeException with code malformedMessageBody including the message code.","triggerScenarios":"A field inside the message body map has an unexpected type (e.g. string where int expected) or a URI-valued field fails URI parsing.","commonSituations":"Corrupted or hand-crafted msgpack payloads, encoder/decoder schema drift, streams produced by non-Pkl tools.","solutions":["Inspect the message code in the error and validate that message's fields against the expected schema","Regenerate the stream with a matching encoder version","Check for text contamination of the binary channel","Catch DecodeException around decode and log the raw payload for diagnosis"],"exampleFix":"// before\nvar msg = decoder.decode(unpacker);\n// after\ntry { var msg = decoder.decode(unpacker); }\ncatch (DecodeException e) { log.warn(\"bad message body (code={})\", e.getMessage(), e); skipFrame(unpacker); }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { return decoder.decode(unpacker); } catch (DecodeException e) { if (String.valueOf(e.getMessage()).startsWith(\"malformedMessageBody\")) { log.warn(\"bad body for code {}\", codeFromMessage(e)); } throw e; }","preventionTips":["Validate msgpack payloads against the message schema","Keep encoder/decoder versions aligned","Capture raw bytes on decode failure for diagnosis"],"tags":["msgpack","decoding","malformed-data"],"backgroundTag":"json-decode-failed","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}