{"record":{"id":"0ac53a910e1ea4c8","repo":"FuelLabs/fuels-ts","slug":"encode-error-0ac53a","errorCode":"ENCODE_ERROR","errorMessage":"Invalid ${this.type}. Field \"${fieldName}\" not present.","messagePattern":"Invalid (.+?)\\. Field \"(.+?)\" not present\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/StructCoder.ts","lineNumber":43,"sourceCode":"  constructor(name: string, coders: TCoders) {\n    const encodedLength = Object.values(coders).reduce(\n      (acc, coder) => acc + coder.encodedLength,\n      0\n    );\n    super('struct', `struct ${name}`, encodedLength);\n    this.name = name;\n    this.coders = coders;\n    this.#hasNestedOption = hasNestedOption(coders);\n  }\n\n  encode(value: InputValueOf<TCoders>): Uint8Array {\n    return concatBytes(\n      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];","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/StructCoder.ts#L25-L61","documentation":"Thrown by StructCoder.encode() when iterating struct fields and encountering a non-Option field whose value is null or undefined. Only fields backed by OptionCoder may be null/undefined; all other field types (u32, b256, bool, str[N], etc.) must have a concrete value. The error message names the specific missing field.","triggerScenarios":"Encoding a struct object where a required field (e.g. u32, b256) is undefined or null. Constructing a struct from partial data without setting all fields. A field name typo in the object causing the actual field to remain undefined.","commonSituations":"Optional application data not fully populated before encoding. An API response with missing keys passed directly to the encoder. The ABI struct definition has more non-Option fields than the client provides.","solutions":["Provide a concrete value for every non-Option field before encoding.","If the field is genuinely nullable, change the ABI type to Option<T> so OptionCoder handles it.","Check for field name typos between the value object and the ABI struct definition."],"exampleFix":"// before\nstructCoder.encode({ a: 1 }); // field 'b' undefined -> ENCODE_ERROR\n\n// after\nstructCoder.encode({ a: 1, b: 0 });\n// or change ABI to b: Option<u32>:\nstructCoder.encode({ a: 1, b: undefined });","handlingStrategy":"validation","validationCode":"function hasAllRequiredFields(value: Record<string, unknown>, requiredFields: string[]): boolean {\n  return requiredFields.every(f => value[f] != null);\n}","typeGuard":"function isCompleteStruct<T extends Record<string, unknown>>(value: unknown, requiredFields: string[]): value is T {\n  if (typeof value !== 'object' || value === null) return false;\n  const obj = value as Record<string, unknown>;\n  return requiredFields.every(f => f in obj && obj[f] != null);\n}","tryCatchPattern":null,"preventionTips":["Use TypeScript types generated from the ABI to catch missing fields at compile time.","Default non-Option struct fields to type-appropriate zero values.","Validate struct completeness before encoding, especially for data from external sources."],"tags":["abi-coder","encoding","struct","validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}