FuelLabs/fuels-ts · error · FuelError
DECODE_ERROR
DECODE_ERROR
Error message
Invalid raw slice data size.
What it means
Thrown by RawSliceCoder.decode() when the data buffer is shorter than WORD_SIZE (8 bytes). The raw slice encoding begins with an 8-byte u64 big-endian length prefix, so any payload smaller than 8 bytes cannot contain even the length header.
Source
Thrown at packages/abi-coder/src/encoding/coders/RawSliceCoder.ts:30
constructor() {
super('raw untyped slice', 'raw untyped slice', WORD_SIZE);
}
encode(value: number[]): Uint8Array {
if (!Array.isArray(value)) {
throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
}
const internalCoder = new ArrayCoder(new NumberCoder('u8'), value.length);
const bytes = internalCoder.encode(value);
const lengthBytes = new BigNumberCoder('u64').encode(bytes.length);
return new Uint8Array([...lengthBytes, ...bytes]);
}
decode(data: Uint8Array, offset: number): [number[], number] {
if (data.length < this.encodedLength) {
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice 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 raw slice byte data size.`);
}
const internalCoder = new ArrayCoder(new NumberCoder('u8'), length);
const [decodedValue] = internalCoder.decode(dataBytes, 0);
return [decodedValue, offsetAndLength + length];
}
}
View on GitHub (pinned to b3f37c91ac)
Solutions
- Verify data.length >= 8 (WORD_SIZE) before calling decode().
- Ensure the data was produced by a compatible encoder or Sway ABI.
- Check for ABI mismatches if data consistently fails this check.
Example fix
// before
rawSliceCoder.decode(new Uint8Array([1, 2, 3]), 0); // throws DECODE_ERROR
// after
const WORD_SIZE = 8;
if (data.length < WORD_SIZE) {
throw new Error('Data too short for raw slice decode');
}
rawSliceCoder.decode(data, 0); Defensive patterns
Strategy: validation
Validate before calling
const WORD_SIZE = 8;
function canDecodeRawSlice(data: Uint8Array): boolean {
return data.length >= WORD_SIZE;
} Prevention
- Validate minimum buffer size (8 bytes) before decoding variable-length types.
- Log data.length on decode failures to identify truncation.
- Use the same ABI version on both sides of the encoding boundary.
When it happens
Trigger: Passing a byte array with fewer than 8 bytes to decode(). Receiving a truncated or empty ABI-encoded raw slice from an RPC call. Using the wrong coder for the data format.
Common situations: Malformed RPC response data. Buffer truncation during network transmission. ABI version mismatch producing differently sized payloads.
Related errors
AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12).
Data as JSON: /api/errors/3ce87c67a381db6b.
Report an issue: GitHub.