{"record":{"id":"a378e603bcde57fd","repo":"apple/pkl","slug":"unhandledmessagetype","errorCode":"unhandledMessageType","errorMessage":"unhandledMessageType","messagePattern":"unhandledMessageType","errorType":"error_code","errorClass":"ProtocolException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/messaging/BaseMessagePackEncoder.java","lineNumber":131,"sourceCode":"        packKeyValue(\"evaluatorId\", m.evaluatorId());\n        packKeyValue(\"uri\", m.uri().toString());\n      }\n      case LIST_MODULES_RESPONSE -> {\n        var m = (ListModulesResponse) msg;\n        packMapHeader(2, m.pathElements(), m.error());\n        packKeyValue(\"requestId\", m.requestId());\n        packKeyValue(\"evaluatorId\", m.evaluatorId());\n        if (m.pathElements() != null) {\n          packer.packString(\"pathElements\");\n          packer.packArrayHeader(m.pathElements().size());\n          for (var pathElement : m.pathElements()) {\n            packPathElement(pathElement);\n          }\n        }\n        packKeyValue(\"error\", m.error());\n      }\n      default ->\n          throw new ProtocolException(\n              ErrorMessages.create(\"unhandledMessageType\", msg.type().toString()));\n    }\n  }\n}\n","sourceCodeStart":113,"sourceCodeEnd":136,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/messaging/BaseMessagePackEncoder.java#L113-L136","documentation":"The encoder's encodeMessage switch has no case for the given message type, so it throws ProtocolException with code unhandledMessageType naming the type. This is an internal exhaustiveness guard when a new message Type is added without encoder support.","triggerScenarios":"Calling BaseMessagePackEncoder.encodeMessage with a Message whose type() is not covered by the switch (e.g. a newly added or custom message type).","commonSituations":"Library upgrades where a new message type was introduced but the encoder (or a subclass overriding encodeMessage) was not updated; custom message types passed to the standard encoder.","solutions":["Upgrade pkl so encoder and message Type definitions are in sync","Add a switch case packing the new message type's fields","Filter out unsupported message types before calling encodeMessage","Route custom types through a dedicated encoder instead"],"exampleFix":"// before\ndefault -> throw new ProtocolException(ErrorMessages.create(\"unhandledMessageType\", msg.type().toString()));\n// after\ncase CAN_EVALUATE -> { packHeader(m.type()); packKeyValue(\"supportedFeatures\", ...); }\ndefault -> throw new ProtocolException(ErrorMessages.create(\"unhandledMessageType\", msg.type().toString()));","handlingStrategy":"type-guard","validationCode":"static boolean isEncodable(Message m) { return java.util.Set.of(Type.EVALUATE, Type.CANCEL_EVALUATE, Type.LOG, ...).contains(m.type()); }","typeGuard":"static boolean canEncode(Message m) { return switch (m.type()) { case EVALUATE, CANCEL_EVALUATE, LOG, READ, OUTDATED -> true; default -> false; }; }","tryCatchPattern":"try { encoder.encodeMessage(msg); } catch (ProtocolException e) { if (String.valueOf(e.getMessage()).contains(\"unhandledMessageType\")) { /* upgrade pkl or drop this message type */ } throw e; }","preventionTips":["Update encoder switch when adding message types","Gate custom message types behind a custom encoder","Run round-trip encode/decode tests in CI"],"tags":["msgpack","encoding","protocol"],"backgroundTag":"unsupported-enum-value","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"}