FuelLabs/fuels-ts · error · FuelError

DECODE_ERROR

DECODE_ERROR

Error message

Invalid number data size.

What it means

Thrown by NumberCoder.decode() when the provided data buffer is shorter than the coder's encodedLength (1/2/4 bytes, or 8 if padToWordSize). The decoder needs at least encodedLength bytes to read a number value; a buffer below that minimum is invalid.

Source

Thrown at packages/abi-coder/src/encoding/coders/NumberCoder.ts:58

  encode(value: number | string): Uint8Array {
    let bytes;

    try {
      bytes = toBytes(value);
    } catch (error) {
      throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);
    }

    if (bytes.length > this.encodedLength) {
      throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);
    }

    return toBytes(bytes, this.encodedLength);
  }

  decode(data: Uint8Array, offset: number): [number, number] {
    if (data.length < this.encodedLength) {
      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);
    }

    const bytes = data.slice(offset, offset + this.encodedLength);

    if (bytes.length !== this.encodedLength) {
      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);
    }

    return [toNumber(bytes), offset + this.encodedLength];
  }
}

View on GitHub (pinned to b3f37c91ac)

Solutions

  1. Verify data.length >= coder.encodedLength before calling decode().
  2. Ensure the data originates from a compatible encode() call or matching ABI source.
  3. Check for ABI or encoding version mismatches between producer and consumer.

Example fix

// before
const coder = new NumberCoder('u32');
coder.decode(new Uint8Array([0, 0]), 0); // throws DECODE_ERROR

// after
const coder = new NumberCoder('u32');
if (data.length < coder.encodedLength) {
  throw new Error(`Need at least ${coder.encodedLength} bytes, got ${data.length}`);
}
coder.decode(data, 0);
Defensive patterns

Strategy: validation

Validate before calling

function canDecodeNumber(data: Uint8Array, coder: NumberCoder): boolean {
  return data.length >= coder.encodedLength;
}

Prevention

When it happens

Trigger: Calling decode() with a byte array shorter than the expected size (e.g., 2 bytes for a u32 coder). Receiving a truncated ABI-encoded payload from an RPC response or log.

Common situations: Malformed or truncated data from a broken RPC endpoint. Manual byte slicing that removes too many bytes. ABI version mismatch causing different encoding sizes.

Related errors


AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12). Data as JSON: /api/errors/ca9530f73529db23. Report an issue: GitHub.