lutzroeder/netron · error · Error

Expected 'begin'.

Error message

Expected 'begin'.

What it means

Generated protobuf requirement check: after decoding a caffe2.TensorProto.Segment from binary, the required field 'begin' was never set. proto2-style required fields must be present; if the wire input never carried field 1, decode() throws before returning the message.

Source

Thrown at source/caffe2-proto.js:173

    static decode(reader, length) {
        const message = new caffe2.TensorProto.Segment();
        const end = length === undefined ? reader.length : reader.position + length;
        while (reader.position < end) {
            const tag = reader.uint32();
            switch (tag >>> 3) {
                case 1:
                    message.begin = reader.int64();
                    break;
                case 2:
                    message.end = reader.int64();
                    break;
                default:
                    reader.skipType(tag & 7);
                    break;
            }
        }
        if (!Object.prototype.hasOwnProperty.call(message, 'begin')) {
            throw new Error("Expected 'begin'.");
        }
        if (!Object.prototype.hasOwnProperty.call(message, 'end')) {
            throw new Error("Expected 'end'.");
        }
        return message;
    }

    static decodeText(reader) {
        const message = new caffe2.TensorProto.Segment();
        reader.start();
        while (!reader.end()) {
            const tag = reader.tag();
            switch (tag) {
                case "begin":
                    message.begin = reader.int64();
                    break;
                case "end":
                    message.end = reader.int64();

View on GitHub (pinned to d8a543f5f8)

Solutions

  1. Validate the source of the .pb file and re-export it from Caffe2
  2. Verify you are decoding the right message type at that position (misaligned stream decodes garbage)
  3. Check the file was transferred fully (checksum/size)
  4. Regenerate the model with a toolchain matching the library's caffe2.proto version
Defensive patterns

Strategy: validation

Validate before calling

// Validate decoded message before use
class Segment { constructor() { this.begin = 0; this.end = 0; } }
const ok = (m) => m instanceof Segment && 'begin' in m && 'end' in m;

Type guard

function isSegment(m) {
  return m != null && typeof m === 'object' &&
    Object.prototype.hasOwnProperty.call(m, 'begin') &&
    Object.prototype.hasOwnProperty.call(m, 'end');
}

Try / catch

try {
  const seg = caffe2.TensorProto.Segment.decode(reader);
} catch (e) {
  if (e.message === "Expected 'begin'.") {
    // mark source model invalid; skip tensor, don't retry
  } else throw e;
}

Prevention

When it happens

Trigger: Decoding a TensorProto.Segment payload (as part of parsing a caffe2 predictor/initials file) whose serialized bytes omit the required 'begin' field — either a truncated message or bytes that aren't actually a Segment.

Common situations: Corrupt or truncated .pb/.init files, version mismatches where an older producer omitted the field, or feeding arbitrary binary to the caffe2 loader so a wrong message type is decoded from those bytes.

Related errors


AI-assisted analysis of lutzroeder/netron@d8a543f5f8 (2026-08-27). Data as JSON: /api/errors/d094fd567f3f15d1. Report an issue: GitHub.