{"id":"f80d4037eed9f7d9","repo":"socketio/socket.io","slug":"unknown-type-obj","errorCode":null,"errorMessage":"Unknown type: ${obj}","messagePattern":"Unknown type: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/socket.io-parser/lib/index.ts","lineNumber":210,"sourceCode":"        this.reconstructor = new BinaryReconstructor(packet);\n      } else {\n        // non-binary full packet\n        super.emitReserved(\"decoded\", packet);\n      }\n    } else if (isBinary(obj) || obj.base64) {\n      // raw binary data\n      if (!this.reconstructor) {\n        throw new Error(\"got binary data when not reconstructing a packet\");\n      } else {\n        packet = this.reconstructor.takeBinaryData(obj);\n        if (packet) {\n          // received final buffer\n          this.reconstructor = null;\n          super.emitReserved(\"decoded\", packet);\n        }\n      }\n    } else {\n      throw new Error(\"Unknown type: \" + obj);\n    }\n  }\n\n  /**\n   * Decode a packet String (JSON data)\n   *\n   * @param {String} str\n   * @return {Object} packet\n   */\n  private decodeString(str): Packet {\n    let i = 0;\n    // look up type\n    const p: any = {\n      type: Number(str.charAt(0)),\n    };\n\n    if (PacketType[p.type] === undefined) {\n      throw new Error(\"unknown packet type \" + p.type);","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/socketio/socket.io/blob/ae7fb46e08c5ed964b4a1ea8b1703e816511598e/packages/socket.io-parser/lib/index.ts#L192-L228","documentation":"Thrown by the parser Decoder.add() when add() receives a value that is neither a string, a binary object (ArrayBuffer/Buffer/Blob), nor an object with base64. The else branch at the end of add() catches any input type the decoder does not know how to dispatch.","triggerScenarios":"Calling decoder.add(value) where value is e.g. a number, boolean, plain object (non-base64), null, or undefined.","commonSituations":"A custom/buggy transport passing non-frame values to the decoder; or a unit test feeding literal numbers/objects instead of encoded packet strings.","solutions":["Ensure only valid encoded inputs reach add(): an encoded packet string, an ArrayBuffer/Buffer/Blob, or a base64 object.","Add an input-type guard at the transport boundary to coerce or reject non-frame values before calling add().","If you control the producer, serialize the packet via the Encoder before sending."],"exampleFix":"// before\ndecoder.add(42); // throws 'Unknown type: 42'\n\n// after\nif (typeof value === 'string' || isBinary(value)) {\n  decoder.add(value);\n} else {\n  throw new TypeError('decoder.add expects a string or binary frame');\n}","handlingStrategy":"type-guard","validationCode":"function isDecodable(obj){\n  return typeof obj==='string' || isBinary(obj) || (obj && typeof obj==='object' && obj.base64);\n}","typeGuard":"function isBinary(x){ return x instanceof ArrayBuffer || (typeof Buffer!=='undefined'&&Buffer.isBuffer(x)) || (typeof Blob!=='undefined'&&x instanceof Blob); }","tryCatchPattern":"if(!isDecodable(value)) throw new TypeError('decoder.add expects a string or binary frame');\ndecoder.add(value);","preventionTips":["Validate input type at the transport boundary before calling add().","Serialize via the Encoder rather than feeding raw values.","Reject numbers/booleans/plain objects in test fixtures."],"tags":["parser","decoder","validation","type-error"],"analyzedSha":"ae7fb46e08c5ed964b4a1ea8b1703e816511598e","analyzedAt":"2026-08-03T19:08:14.127Z","schemaVersion":2}