{"record":{"id":"3d799457509cae8f","repo":"FuelLabs/fuels-ts","slug":"decode-error-3d7994","errorCode":"DECODE_ERROR","errorMessage":"Invalid struct data size.","messagePattern":"Invalid struct data size\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/StructCoder.ts","lineNumber":56,"sourceCode":"      Object.keys(this.coders).map((fieldName) => {\n        const fieldCoder = this.coders[fieldName];\n        const fieldValue = value[fieldName];\n\n        if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {\n          throw new FuelError(\n            ErrorCode.ENCODE_ERROR,\n            `Invalid ${this.type}. Field \"${fieldName}\" not present.`\n          );\n        }\n\n        return fieldCoder.encode(fieldValue);\n      })\n    );\n  }\n\n  decode(data: Uint8Array, offset: number): [DecodedValueOf<TCoders>, number] {\n    if (!this.#hasNestedOption && data.length < this.encodedLength) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid struct data size.`);\n    }\n\n    let newOffset = offset;\n    const decodedValue = Object.keys(this.coders).reduce((obj, fieldName) => {\n      const fieldCoder = this.coders[fieldName];\n      let decoded;\n      [decoded, newOffset] = fieldCoder.decode(data, newOffset);\n\n      // eslint-disable-next-line no-param-reassign\n      obj[fieldName as keyof DecodedValueOf<TCoders>] = decoded;\n      return obj;\n    }, {} as DecodedValueOf<TCoders>);\n\n    return [decodedValue, newOffset];\n  }\n}\n","sourceCodeStart":38,"sourceCodeEnd":73,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/StructCoder.ts#L38-L73","documentation":"Thrown by StructCoder.decode() when the struct has no nested Option fields and the data buffer is shorter than the struct's total encoded length (sum of all field encoded lengths). Without nested Options the struct is fixed-size, so the buffer must be at least that large. Structs with nested Option fields skip this check because Option encoding is variable-length.","triggerScenarios":"Decoding a truncated buffer that does not contain enough bytes for all struct fields. ABI mismatch where the struct layout differs between encoder and decoder. Using the wrong struct coder for the data format.","commonSituations":"Malformed RPC data. ABI version mismatch between contract and client. Manual data construction with incorrect sizing.","solutions":["Verify data.length >= structCoder.encodedLength before calling decode().","Ensure the struct coder matches the ABI struct definition exactly.","Check for data truncation in the pipeline."],"exampleFix":"// before\nstructCoder.decode(truncatedData, 0); // throws DECODE_ERROR\n\n// after\nif (data.length < structCoder.encodedLength) {\n  throw new Error(`Need ${structCoder.encodedLength} bytes, got ${data.length}`);\n}\nstructCoder.decode(data, 0);","handlingStrategy":"validation","validationCode":"function canDecodeStruct(data: Uint8Array, encodedLength: number): boolean {\n  return data.length >= encodedLength;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate buffer size against the struct encodedLength before decoding.","Keep ABI definitions in sync between contract and client.","Log expected vs actual lengths on decode failures."],"tags":["abi-coder","decoding","struct","data-validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}