{"record":{"id":"dd75d22b6dbe0dc0","repo":"lutzroeder/netron","slug":"expected-key","errorCode":null,"errorMessage":"Expected 'key'.","messagePattern":"Expected 'key'\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"source/caffe2-proto.js","lineNumber":1070,"sourceCode":"    static decode(reader, length) {\n        const message = new caffe2.MapFieldEntry();\n        const end = length === undefined ? reader.length : reader.position + length;\n        while (reader.position < end) {\n            const tag = reader.uint32();\n            switch (tag >>> 3) {\n                case 1:\n                    message.key = reader.string();\n                    break;\n                case 2:\n                    message.val = reader.string();\n                    break;\n                default:\n                    reader.skipType(tag & 7);\n                    break;\n            }\n        }\n        if (!Object.prototype.hasOwnProperty.call(message, 'key')) {\n            throw new Error(\"Expected 'key'.\");\n        }\n        if (!Object.prototype.hasOwnProperty.call(message, 'val')) {\n            throw new Error(\"Expected 'val'.\");\n        }\n        return message;\n    }\n\n    static decodeText(reader) {\n        const message = new caffe2.MapFieldEntry();\n        reader.start();\n        while (!reader.end()) {\n            const tag = reader.tag();\n            switch (tag) {\n                case \"key\":\n                    message.key = reader.string();\n                    break;\n                case \"val\":\n                    message.val = reader.string();","sourceCodeStart":1052,"sourceCodeEnd":1088,"githubUrl":"https://github.com/lutzroeder/netron/blob/d8a543f5f847ef596aa58858d6adcf5d75545f7f/source/caffe2-proto.js#L1052-L1088","documentation":"This is the binary decoder for caffe2.MapFieldEntry (a map<string,string> entry) rejecting input where the required 'key' field is absent. Protobuf map entries encode key and val as ordinary fields, and the generated verifier requires both to be present in the wire data.","triggerScenarios":"caffe2.MapFieldEntry.decode(reader) on bytes that contain only a val field (or neither), e.g. hand-crafted wire bytes, buffers sliced at the wrong offset, or a map entry serialized by a producer that omits keys.","commonSituations":"Parsing caffe2 operator args or device options stored as maps; misaligned buffer slicing when extracting sub-messages from a larger blob; feeding malformed fixtures into tests.","solutions":["Verify the byte slice boundaries so the MapFieldEntry starts at the correct offset and includes the key field.","Re-serialize the source map with a correct encoder so every entry has both key and val.","If consuming JSON, use decodeText and ensure each entry object has a 'key' property.","Add a length/field sanity check on the buffer before calling decode."],"exampleFix":"// before\nconst entry = caffe2.MapFieldEntry.decode(buf.subarray(0, len)); // throws Expected 'key'\n\n// after\nconst entry = caffe2.MapFieldEntry.decode(buf.subarray(start, start + entryLen));\nif (typeof entry.key !== 'string') throw new TypeError('bad map entry');","handlingStrategy":"try-catch","validationCode":"// Binary wire: check first byte is field 1 tag (0x0A) before decode\nfunction looksLikeMapEntry(u8){return u8.length>0 && (u8[0]&7)===2 && (u8[0]>>3)===1;}","typeGuard":"function isMapEntry(o){return !!o && typeof o.key==='string' && typeof o.val==='string';}","tryCatchPattern":"try { entry = caffe2.MapFieldEntry.decode(bytes); } catch (e) { if (/Expected 'key'/.test(e.message)) { skipOrReencode(bytes); } else throw e; }","preventionTips":["Decode parent messages rather than slicing raw bytes.","Use the library's own encode() to produce test fixtures.","Assert buffer offsets/lengths before sub-decoding."],"tags":["protobuf","map-entry","required-field","caffe2"],"backgroundTag":"protobuf-missing-required-field","analyzedSha":"d8a543f5f847ef596aa58858d6adcf5d75545f7f","analyzedAt":"2026-08-27T19:21:42.082Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}