{"record":{"id":"ca9530f73529db23","repo":"FuelLabs/fuels-ts","slug":"decode-error-ca9530","errorCode":"DECODE_ERROR","errorMessage":"Invalid number data size.","messagePattern":"Invalid number data size\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/NumberCoder.ts","lineNumber":58,"sourceCode":"  encode(value: number | string): Uint8Array {\n    let bytes;\n\n    try {\n      bytes = toBytes(value);\n    } catch (error) {\n      throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}.`);\n    }\n\n    if (bytes.length > this.encodedLength) {\n      throw new FuelError(ErrorCode.ENCODE_ERROR, `Invalid ${this.baseType}, too many bytes.`);\n    }\n\n    return toBytes(bytes, this.encodedLength);\n  }\n\n  decode(data: Uint8Array, offset: number): [number, number] {\n    if (data.length < this.encodedLength) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number data size.`);\n    }\n\n    const bytes = data.slice(offset, offset + this.encodedLength);\n\n    if (bytes.length !== this.encodedLength) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid number byte data size.`);\n    }\n\n    return [toNumber(bytes), offset + this.encodedLength];\n  }\n}\n","sourceCodeStart":40,"sourceCodeEnd":70,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/NumberCoder.ts#L40-L70","documentation":"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.","triggerScenarios":"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.","commonSituations":"Malformed or truncated data from a broken RPC endpoint. Manual byte slicing that removes too many bytes. ABI version mismatch causing different encoding sizes.","solutions":["Verify data.length >= coder.encodedLength before calling decode().","Ensure the data originates from a compatible encode() call or matching ABI source.","Check for ABI or encoding version mismatches between producer and consumer."],"exampleFix":"// before\nconst coder = new NumberCoder('u32');\ncoder.decode(new Uint8Array([0, 0]), 0); // throws DECODE_ERROR\n\n// after\nconst coder = new NumberCoder('u32');\nif (data.length < coder.encodedLength) {\n  throw new Error(`Need at least ${coder.encodedLength} bytes, got ${data.length}`);\n}\ncoder.decode(data, 0);","handlingStrategy":"validation","validationCode":"function canDecodeNumber(data: Uint8Array, coder: NumberCoder): boolean {\n  return data.length >= coder.encodedLength;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always validate buffer length against coder.encodedLength before decode().","Log expected vs actual data length when debugging decode failures.","Ensure ABI-encoded payloads are not truncated during transit."],"tags":["abi-coder","decoding","number","data-validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}