FuelLabs/fuels-ts · error · FuelError
DECODE_ERROR
DECODE_ERROR
Error message
Invalid byte data size.
What it means
Thrown by ByteCoder.decode at the top guard: data.length < WORD_SIZE (8). The message is the literal "Invalid byte data size.". A Sway Bytes value is length-prefixed by a u64, so at least 8 bytes are needed just to read the length. Fewer than 8 bytes means the payload cannot contain the length header.
Source
Thrown at packages/abi-coder/src/encoding/coders/ByteCoder.ts:24
import { Coder } from './AbstractCoder';
import { BigNumberCoder } from './BigNumberCoder';
export class ByteCoder extends Coder<number[], Uint8Array> {
static memorySize = 1;
constructor() {
super('struct', 'struct Bytes', WORD_SIZE);
}
encode(value: number[] | Uint8Array): Uint8Array {
const bytes = value instanceof Uint8Array ? value : new Uint8Array(value);
const lengthBytes = new BigNumberCoder('u64').encode(bytes.length);
return new Uint8Array([...lengthBytes, ...bytes]);
}
decode(data: Uint8Array, offset: number): [Uint8Array, number] {
if (data.length < WORD_SIZE) {
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte data size.`);
}
const offsetAndLength = offset + WORD_SIZE;
const lengthBytes = data.slice(offset, offsetAndLength);
const length = bn(new BigNumberCoder('u64').decode(lengthBytes, 0)[0]).toNumber();
const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);
if (dataBytes.length !== length) {
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);
}
return [dataBytes, offsetAndLength + length];
}
}
View on GitHub (pinned to b3f37c91ac)
Solutions
- Verify data.length >= WORD_SIZE (8) before decode.
- Confirm the bytes actually represent a length-prefixed Sway Bytes value.
- Let AbiCoder handle offset/prefix bookkeeping.
Defensive patterns
Strategy: try-catch
Validate before calling
if (data.length < 8) throw new Error('need >= 8 bytes for Bytes length header')
byteCoder.decode(data, offset) Type guard
const canDecodeBytes = (data: Uint8Array) => data.length >= 8
Try / catch
try { byteCoder.decode(data, offset) }
catch (e) { if ((e as FuelError).code === ErrorCode.DECODE_ERROR) { /* payload too short / wrong coder */ } throw e } Prevention
- Ensure the buffer carries the u64 length prefix intact.
- Use the framework decoder rather than manual slicing.
- Validate at least WORD_SIZE bytes are present before decode.
When it happens
Trigger: Calling byteVec.decode(data, offset) with data shorter than 8 bytes, e.g. a truncated or empty payload, or a wrong offset leaving fewer than 8 bytes.
Common situations: Truncated Bytes return data from the provider; wrong coder applied to the bytes; manual offset advanced past the length header; decoding an empty/garbage buffer.
Related errors
AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12).
Data as JSON: /api/errors/4e5cef0402a0cd2c.
Report an issue: GitHub.