hyperledger/fabric · error

unexpected error while unmarshalling bytes [%#v] into fileLo

Error message

unexpected error while unmarshalling bytes [%#v] into fileLocPointer

What it means

fileLocPointer.unmarshal decodes a protowire-encoded sequence of three varints (fileSuffixNum, offset, bytesLength) from the index DB value. When the first varint cannot be consumed (malformed protobuf wire data), the parse error is wrapped with this message. It indicates the stored index value is not a valid fileLocPointer encoding.

Source

Thrown at common/ledger/blkstorage/blockindex.go:525

	flp.bytesLength = relativeLP.bytesLength
	return flp
}

func (flp *fileLocPointer) marshal() []byte {
	var buf []byte
	buf = protowire.AppendVarint(buf, uint64(flp.fileSuffixNum))
	buf = protowire.AppendVarint(buf, uint64(flp.offset))
	buf = protowire.AppendVarint(buf, uint64(flp.bytesLength))

	return buf
}

func (flp *fileLocPointer) unmarshal(b []byte) error {
	var position int

	i, n := protowire.ConsumeVarint(b[position:])
	if n < 0 {
		return errors.Wrapf(protowire.ParseError(n), "unexpected error while unmarshalling bytes [%#v] into fileLocPointer", b)
	}
	position += n
	flp.fileSuffixNum = int(i)

	i, n = protowire.ConsumeVarint(b[position:])
	if n < 0 {
		return errors.Wrapf(protowire.ParseError(n), "unexpected error while unmarshalling bytes [%#v] into fileLocPointer", b)
	}
	position += n
	flp.offset = int(i)

	i, n = protowire.ConsumeVarint(b[position:])
	if n < 0 {
		return errors.Wrapf(protowire.ParseError(n), "unexpected error while unmarshalling bytes [%#v] into fileLocPointer", b)
	}
	flp.bytesLength = int(i)
	return nil
}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Inspect the %#v bytes in the message to confirm the value is garbage/empty rather than valid varints.
  2. Rebuild the block index: stop the peer, delete the index DB (or the whole ledgerDB), and resync/rejoin the channel.
  3. Confirm all peers/ledgers come from compatible Fabric versions; do not mix ledger files across versions without migration.
  4. Check for disk errors or unclean shutdowns that may have corrupted the store.
Defensive patterns

Strategy: try-catch

Try / catch

loc := &blkstorage.FileLocPointer{}
if err := loc.Unmarshal(indexValue); err != nil {
    if strings.Contains(err.Error(), "unexpected error while unmarshalling bytes") {
        return fmt.Errorf("corrupt index value for key %x: %w — schedule index rebuild", key, err)
    }
    return err
}

Prevention

When it happens

Trigger: Called from getBlockLocByHash, getBlockLocByBlockNum, getTxLoc, getBlockLocByTxID, or getTXLocByBlockNumTranNum when the index DB value under the looked-up key is corrupted, empty/truncated, or was written by an incompatible encoding version.

Common situations: LevelDB corruption after unclean shutdown, mixed-version ledgers where the value encoding changed, manually copied ledger directories missing/corrupting index values.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/567942f4a6b17869. Report an issue: GitHub.