FuelLabs/fuels-ts · error · FuelError

DECODE_ERROR

DECODE_ERROR

Error message

Invalid boolean data size.

What it means

Thrown by BooleanCoder.decode at the top guard: data.length < this.encodedLength. encodedLength is 1 by default, or WORD_SIZE (8) when padToWordSize is set. Message: "Invalid boolean data size.". The buffer is too short to hold even one boolean value.

Source

Thrown at packages/abi-coder/src/encoding/coders/BooleanCoder.ts:35

    const encodedLength = options.padToWordSize ? WORD_SIZE : 1;
    super('boolean', 'boolean', encodedLength);

    this.options = options;
  }

  encode(value: boolean): Uint8Array {
    const isTrueBool = value === true || value === false;

    if (!isTrueBool) {
      throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid boolean value.`);
    }

    return toBytes(value ? 1 : 0, this.encodedLength);
  }

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

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

    if (bytes.isZero()) {
      return [false, offset + this.encodedLength];
    }

    if (!bytes.eq(bn(1))) {
      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid boolean value.`);
    }

    return [true, offset + this.encodedLength];
  }
}

View on GitHub (pinned to b3f37c91ac)

Solutions

  1. Confirm data.length >= this.encodedLength before decode.
  2. Ensure the boolean's padToWordSize option matches how the data was encoded.
  3. Use the high-level decoder to track offsets and padding automatically.
Defensive patterns

Strategy: try-catch

Validate before calling

if (data.length < boolCoder.encodedLength) throw new Error('buffer too short for boolean')
bool.decode(data, offset)

Type guard

const canDecodeBoolean = (data: Uint8Array, len: number) => data.length >= len

Try / catch

try { bool.decode(data, offset) }
catch (e) { if ((e as FuelError).code === ErrorCode.DECODE_ERROR) { /* check length/padding */ } throw e }

Prevention

When it happens

Trigger: Calling bool.decode(data, offset) with data shorter than the expected length (1 byte, or 8 bytes when padded). Common with truncated payloads or wrong offset.

Common situations: Truncated receipt/log data; using a padded boolean coder against unpadded data (or vice-versa); manual offset advanced past available bytes.

Related errors


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