can1357/oh-my-pi · error · Error

Unsupported protobuf wire type ${wireType} at byte ${reader.

Error message

Unsupported protobuf wire type ${wireType} at byte ${reader.pos}

What it means

Thrown by the compiled protobuf codec while scanning a message: the tag's low 3 bits encode a wire type outside the set the codec understands (0 varint, 1 64-bit, 2 length-delimited, 5 32-bit). This means the bytes are not a valid message for this schema — either the payload is corrupt/truncated, or it's not protobuf at all.

Source

Thrown at packages/catalog/src/discovery/protobuf.ts:262

			f.encode(value, writer);
		}
		writeUnknownFields(value, writer);
		return writer.finish();
	};

	codec.decode = (value: Uint8Array): T => {
		const reader = new Reader(value);
		const message = (typeName ? { $typeName: typeName } : {}) as T;
		for (const f of compiledFields) {
			f.initDefault(message);
		}

		while (reader.pos < reader.len) {
			const tag = reader.uint32();
			const fieldNumber = tag >>> 3;
			const wireType = tag & 7;
			if (!isWireType(wireType)) {
				throw new Error(`Unsupported protobuf wire type ${wireType} at byte ${reader.pos}`);
			}
			const field = byNumber.get(fieldNumber);
			if (field) {
				field.decode(message, reader, wireType, fieldNumber);
			} else {
				const start = reader.pos;
				reader.skip(wireType);
				appendUnknownField(message, {
					no: fieldNumber,
					wireType,
					data: reader.slice(start, reader.pos),
				});
			}
		}
		return message;
	};

	codec.toJson = (value: T): JsonValue => {

View on GitHub (pinned to 9690622007)

Solutions

  1. Verify the bytes being decoded are actually protobuf (log the first bytes; JSON starts with '{', HTML with '<').
  2. Check you're decoding the correct message type/scheme for this endpoint's response.
  3. Ensure the buffer is complete — wire type 3/4 can appear when reading past a truncated message.
  4. Capture the raw response and re-run it through `protoc --decode_raw` to identify the real field layout.

Example fix

// before: decoding whatever came back
const msg = codec.decode(new Uint8Array(await res.arrayBuffer()));
// after: guard content type first
if (!res.headers.get("content-type")?.includes("protobuf")) throw new Error("unexpected response");
const msg = codec.decode(new Uint8Array(await res.arrayBuffer()));
Defensive patterns

Strategy: try-catch

Validate before calling

// sanity-check the payload looks like protobuf before decoding
function looksProtobuf(buf: Uint8Array): boolean {
  if (buf.length === 0) return false;
  const first = buf[0];
  return first !== 0x7b /* '{' */ && first !== 0x3c /* '<' */;
}

Type guard

function isUint8Array(v: unknown): v is Uint8Array {
  return v instanceof Uint8Array;
}

Try / catch

try {
  const msg = codec.decode(bytes);
} catch (err) {
  if (err.message.startsWith("Unsupported protobuf wire type")) {
    throw new Error(`payload is not valid protobuf for this schema (first bytes: ${[...bytes.slice(0, 8)]})`);
  }
  throw err;
}

Prevention

When it happens

Trigger: getCodec(...).decode on a buffer where a field tag decodes to wire type 3/4/6/7 (deprecated group start/end or garbage), typically from feeding the decoder non-protobuf bytes, a wrong message's bytes, or a mid-stream truncated buffer.

Common situations: Decoding an HTTP response body that is actually JSON/HTML (proxy error page) instead of protobuf; parsing a concatenated stream without length prefixes; offsetting into the buffer past the message start.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/e6b449c6e3d39a69. Report an issue: GitHub.