{"record":{"id":"85b3146d0331943f","repo":"FuelLabs/fuels-ts","slug":"decode-error-85b314","errorCode":"DECODE_ERROR","errorMessage":"Invalid array data size.","messagePattern":"Invalid array data size\\.","errorType":"error_code","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/ArrayCoder.ts","lineNumber":42,"sourceCode":"    this.length = length;\n    this.#hasNestedOption = hasNestedOption([coder]);\n  }\n\n  encode(value: InputValueOf<TCoder>): Uint8Array {\n    if (!Array.isArray(value)) {\n      throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);\n    }\n\n    if (this.length !== value.length) {\n      throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);\n    }\n\n    return concat(Array.from(value).map((v) => this.coder.encode(v)));\n  }\n\n  decode(data: Uint8Array, offset: number): [DecodedValueOf<TCoder>, number] {\n    if ((!this.#hasNestedOption && data.length < this.encodedLength) || data.length > MAX_BYTES) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid array data size.`);\n    }\n\n    let newOffset = offset;\n    const decodedValue = Array(this.length)\n      .fill(0)\n      .map(() => {\n        let decoded;\n        [decoded, newOffset] = this.coder.decode(data, newOffset);\n        return decoded;\n      });\n\n    return [decodedValue as DecodedValueOf<TCoder>, newOffset];\n  }\n}\n","sourceCodeStart":24,"sourceCodeEnd":57,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/ArrayCoder.ts#L24-L57","documentation":"Thrown by `ArrayCoder.decode` (code `DECODE_ERROR`) when the byte buffer is too small for the declared array's encoded length (and there is no nested `Option` to allow short reads) OR the buffer exceeds `MAX_BYTES`. Guards against underflow and runaway buffers during decoding.","triggerScenarios":"Decoding a return/script-data buffer that was truncated; passing a slice computed with a wrong offset that cuts into the middle of the array; feeding an absurdly large buffer (`> MAX_BYTES`) such as a whole transaction where a slice was expected.","commonSituations":"ABI/bytecode drift causing return data of unexpected size; wrong offset passed when manually decoding nested types; reading from a receipt whose `data` field is shorter than the ABI implies.","solutions":["Verify the byte buffer length matches `arrayCoder.encodedLength` (i.e. `length * elementCoder.encodedLength`).","Re-check the offset used when slicing; ensure `offset + encodedLength <= data.length`.","Regenerate bindings to make sure the ABI matches the deployed contract's actual return layout.","If the buffer is genuinely huge, confirm you are not passing the whole payload instead of the relevant slice."],"exampleFix":"// before\nconst [decoded] = arrayCoder.decode(data, data.length - 4); // slice too short\n// after — pass a buffer/offset that gives the full encodedLength\nconst [decoded] = arrayCoder.decode(data, offset);","handlingStrategy":"try-catch","validationCode":"const need = arrayCoder.encodedLength;\nif (data.length < need || data.length > MAX_BYTES) {\n  throw new Error(`Buffer of ${data.length} bytes cannot decode [T; ${arrayCoder.length}] (need ${need})`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const [val, off] = arrayCoder.decode(data, offset);\n} catch (e) {\n  if (e.code === 'DECODE_ERROR' && /Invalid array data size/.test(e.message)) {\n    // buffer/offset wrong — re-derive the slice and retry\n  }\n  throw e;\n}","preventionTips":["Ensure `data.length >= arrayCoder.encodedLength` and the offset leaves enough bytes.","Keep ABI in sync with deployed contract to avoid return-size drift.","Decode with the parent coder so offsets advance correctly."],"tags":["abi-coder","decoding","array","bounds"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}