FuelLabs/fuels-ts · error · FuelError
DECODE_ERROR
DECODE_ERROR
Error message
Invalid enum data size.
What it means
Thrown by EnumCoder.decode at the first length guard: this.#shouldValidateLength is true and data.length < this.encodedLength. encodedLength is the case-index (8) plus the minimum value size. Message: "Invalid enum data size.". Note length validation is skipped for Option/nested-option enums (#shouldValidateLength is false), so this only fires for regular enums.
Source
Thrown at packages/abi-coder/src/encoding/coders/EnumCoder.ts:93
.join(', ');
throw new FuelError(
ErrorCode.INVALID_DECODE_VALUE,
`Invalid case '${caseKey}'. Valid cases: ${validCases}.`
);
}
const encodedValue = valueCoder.encode(value[caseKey]);
return new Uint8Array([...this.#caseIndexCoder.encode(caseIndex), ...encodedValue]);
}
#decodeNativeEnum(caseKey: string, newOffset: number): [DecodedValueOf<TCoders>, number] {
return [caseKey as unknown as DecodedValueOf<TCoders>, newOffset];
}
decode(data: Uint8Array, offset: number): [DecodedValueOf<TCoders>, number] {
if (this.#shouldValidateLength && data.length < this.encodedLength) {
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
}
const caseBytes = new BigNumberCoder('u64').decode(data, offset)[0];
const caseIndex = toNumber(caseBytes);
const caseKey = Object.keys(this.coders)[caseIndex];
if (!caseKey) {
throw new FuelError(
ErrorCode.INVALID_DECODE_VALUE,
`Invalid caseIndex "${caseIndex}". Valid cases: ${Object.keys(this.coders)}.`
);
}
const valueCoder = this.coders[caseKey];
const offsetAndCase = offset + this.#caseIndexCoder.encodedLength;
if (this.#shouldValidateLength && data.length < offsetAndCase + valueCoder.encodedLength) {
throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid enum data size.`);
}
View on GitHub (pinned to b3f37c91ac)
Solutions
- Confirm data.length >= enumCoder.encodedLength before decode.
- Verify you are using the correct enum coder for the data.
- Let the high-level decoder manage offsets.
Defensive patterns
Strategy: try-catch
Validate before calling
if (enumCoder['#shouldValidateLength'] !== false && data.length < enumCoder.encodedLength) {
throw new Error('buffer too short for enum')
}
enumCoder.decode(data, offset) Type guard
const canDecodeEnum = (data: Uint8Array, len: number) => data.length >= len
Try / catch
try { enumCoder.decode(data, offset) }
catch (e) { if ((e as FuelError).code === ErrorCode.DECODE_ERROR) { /* truncated payload / wrong coder */ } throw e } Prevention
- Confirm the buffer is the full encoded enum.
- Use the correct enum coder (regular vs Option).
- Prefer the high-level decoder.
When it happens
Trigger: Decoding a non-Option enum from a buffer shorter than the enum's encoded length (case index + value). Common with truncated return data or wrong coder.
Common situations: Truncated receipt/return data; decoding at a wrong offset; using a regular-enum coder on data that is actually an Option; provider truncation.
Related errors
AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12).
Data as JSON: /api/errors/1e4734c6e5d0598f.
Report an issue: GitHub.