dagger/dagger · error

decode field of length %d: only %d bytes remain

Error message

decode field of length %d: only %d bytes remain

What it means

Returned by rowDecoder.take when a decoded field length exceeds the bytes remaining in the buffer. The row data is truncated or corrupt: a varint length prefix claims more bytes than the buffer holds, indicating a torn write or version-mismatched encoding in the client DB store.

Source

Thrown at engine/clientdb/store_codec.go:110

func (d *rowDecoder) length() (int, error) {
	v, n := binary.Uvarint(d.buf[d.off:])
	if n == 0 {
		return 0, fmt.Errorf("decode length: truncated varint")
	}
	if n < 0 {
		return 0, fmt.Errorf("decode length: varint overflow")
	}
	d.off += n
	if v > uint64(maxInt) {
		return 0, fmt.Errorf("decode length: %d overflows int", v)
	}
	return int(v), nil
}

func (d *rowDecoder) take(n int) ([]byte, error) {
	if n < 0 || n > len(d.buf)-d.off {
		return nil, fmt.Errorf("decode field of length %d: only %d bytes remain", n, len(d.buf)-d.off)
	}
	v := d.buf[d.off : d.off+n]
	d.off += n
	return v, nil
}

func (d *rowDecoder) string() (string, error) {
	n, err := d.length()
	if err != nil {
		return "", err
	}
	v, err := d.take(n)
	if err != nil {
		return "", err
	}
	return string(v), nil
}

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Handle the error by discarding/rebuilding the corrupt DB row
  2. Verify encoder and decoder agree on the row format version
  3. Add checksums to detect torn writes at ingestion
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at engine/clientdb/store_codec.go:110 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/a0e9a650f6b03ee5. Report an issue: GitHub.