{"record":{"id":"be294eb1501d84c8","repo":"lutzroeder/netron","slug":"expected-val","errorCode":null,"errorMessage":"Expected 'val'.","messagePattern":"Expected 'val'\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"source/caffe2-proto.js","lineNumber":1073,"sourceCode":"        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();\n                    break;\n                default:\n                    reader.field(tag, message);","sourceCodeStart":1055,"sourceCodeEnd":1091,"githubUrl":"https://github.com/lutzroeder/netron/blob/d8a543f5f847ef596aa58858d6adcf5d75545f7f/source/caffe2-proto.js#L1055-L1091","documentation":"Generated binary decoder for caffe2.MapFieldEntry throws when the decoded wire data lacks the required 'val' field. Since MapFieldEntry backs protobuf map<string,string> fields, an entry missing val means the serialized map data is incomplete or corrupt.","triggerScenarios":"MapFieldEntry.decode() over bytes containing a key but no val field; commonly caused by wrong sub-buffer offsets, encoder bugs in the producer, or truncated payloads.","commonSituations":"Extracting and decoding individual map entries from caffe2 Argument/DeviceOption blobs; interoperating with encoders that skip empty-string values; test fixtures with partial entries.","solutions":["Re-encode the map so each entry writes both key and val (even empty strings).","Fix the subarray offset/length used to slice the entry bytes from the parent buffer.","Validate the buffer contains both fields (tags 1 and 2) before decoding.","Fall back to decodeText with complete JSON entries if the binary path is unreliable."],"exampleFix":"// before\nconst e = caffe2.MapFieldEntry.decode(bytes); // throws Expected 'val'\n\n// after\nconst ok = /\u0000/.test('') || bytes.length > 0;\nconst e = caffe2.MapFieldEntry.decode(bytes);\nif (!('val' in e)) throw new RangeError('map entry missing val; re-encode source map');","handlingStrategy":"try-catch","validationCode":"function mapEntryWireOk(u8){return u8.some((b,i)=>i===0?b===0x0A:b===0x12);} // crude presence check for tags 1 and 2","typeGuard":"const isFullEntry = (o) => o && typeof o.key==='string' && 'val' in o;","tryCatchPattern":"try { e = caffe2.MapFieldEntry.decode(bytes); } catch (e2) { if (/Expected 'val'/.test(e2.message)) throw new DataError('corrupt map entry', {bytes}); else throw e2; }","preventionTips":["Never construct map-entry bytes by hand.","Re-encode maps with protobufjs rather than custom writers.","Check payload integrity (CRC/length) before decode."],"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"}