microsoft/typescript-go · error · ErrInvalidRequest

%w: expected positive fixint or uint8 marker, received: 0x%0

Error message

%w: expected positive fixint or uint8 marker, received: 0x%02x

What it means

The second byte of a tuple must encode the message type as a msgpack positive fixint (0x00-0x7f, the byte is the value) or a uint8 marker (0xCC followed by one value byte). Any other marker - negative fixint, string, array - means the stream is misaligned by one byte or the peer is not writing this format. Wraps ErrInvalidRequest.

Source

Thrown at internal/api/protocol_msgpack.go:122

	}

	// Read message type - can be positive fixint (0x00-0x7F) or uint8 (0xCC + value)
	t, err = p.r.ReadByte()
	if err != nil {
		return 0, "", nil, err
	}
	var rawType byte
	if t <= 0x7F {
		// Positive fixint - the byte IS the value
		rawType = t
	} else if t == msgpackU8 {
		// uint8 marker - next byte is the value
		rawType, err = p.r.ReadByte()
		if err != nil {
			return 0, "", nil, err
		}
	} else {
		return 0, "", nil, fmt.Errorf("%w: expected positive fixint or uint8 marker, received: 0x%02x", ErrInvalidRequest, t)
	}
	msgType := MessageType(rawType)
	if !msgType.IsValid() {
		return 0, "", nil, fmt.Errorf("%w: unknown message type: %d", ErrInvalidRequest, msgType)
	}

	// Read method (binary)
	methodBytes, err := p.readBin()
	if err != nil {
		return 0, "", nil, err
	}
	method := string(methodBytes)

	// Read payload (binary)
	payload, err := p.readBin()
	if err != nil {
		return 0, "", nil, err
	}

View on GitHub (pinned to 1bcfa18d79)

Solutions

  1. Use the reference encoding: 0x93, raw type byte, then bin8/16/32 fields
  2. There is no in-stream resync - close and reopen the connection after a framing error
  3. Check that nothing else reads from the same underlying conn
  4. Add a length-prefix or checksum layer if the transport is lossy

Example fix

# before (peer writes type as msgpack str)
93 a1 02 ... 

# after (reference encoding: fixint type byte)
93 02 c4 0b 6765744469676e6f7374696373 ...
Defensive patterns

Strategy: try-catch

Try / catch

if err != nil && errors.Is(err, api.ErrInvalidRequest) {
	log.Printf("bad type marker byte 0x%02x: stream misaligned; resetting connection", t)
	return resetConnection()
}

Prevention

When it happens

Trigger: Same desync causes as the 0x93 failure but shifted one byte; a non-reference encoder emitting msgpack strings or arrays for the type field.

Common situations: Hand-rolled msgpack encoders in other-language clients using str markers for small integers; byte insertion/deletion by a faulty transport.

Related errors


AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16). Data as JSON: /api/errors/04408b9b40af65cc. Report an issue: GitHub.