lutzroeder/netron · error · Error
Expected 'val'.
Error message
Expected 'val'.
What it means
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.
Source
Thrown at source/caffe2-proto.js:1073
while (reader.position < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.key = reader.string();
break;
case 2:
message.val = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
}
}
if (!Object.prototype.hasOwnProperty.call(message, 'key')) {
throw new Error("Expected 'key'.");
}
if (!Object.prototype.hasOwnProperty.call(message, 'val')) {
throw new Error("Expected 'val'.");
}
return message;
}
static decodeText(reader) {
const message = new caffe2.MapFieldEntry();
reader.start();
while (!reader.end()) {
const tag = reader.tag();
switch (tag) {
case "key":
message.key = reader.string();
break;
case "val":
message.val = reader.string();
break;
default:
reader.field(tag, message);View on GitHub (pinned to d8a543f5f8)
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.
Example fix
// before
const e = caffe2.MapFieldEntry.decode(bytes); // throws Expected 'val'
// after
const ok = / /.test('') || bytes.length > 0;
const e = caffe2.MapFieldEntry.decode(bytes);
if (!('val' in e)) throw new RangeError('map entry missing val; re-encode source map'); Defensive patterns
Strategy: try-catch
Validate before calling
function mapEntryWireOk(u8){return u8.some((b,i)=>i===0?b===0x0A:b===0x12);} // crude presence check for tags 1 and 2 Type guard
const isFullEntry = (o) => o && typeof o.key==='string' && 'val' in o;
Try / catch
try { e = caffe2.MapFieldEntry.decode(bytes); } catch (e2) { if (/Expected 'val'/.test(e2.message)) throw new DataError('corrupt map entry', {bytes}); else throw e2; } Prevention
- Never construct map-entry bytes by hand.
- Re-encode maps with protobufjs rather than custom writers.
- Check payload integrity (CRC/length) before decode.
When it happens
Trigger: 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.
Common situations: Extracting and decoding individual map entries from caffe2 Argument/DeviceOption blobs; interoperating with encoders that skip empty-string values; test fixtures with partial entries.
Related errors
AI-assisted analysis of lutzroeder/netron@d8a543f5f8 (2026-08-27).
Data as JSON: /api/errors/be294eb1501d84c8.
Report an issue: GitHub.