{"record":{"id":"f571dc5e5733835c","repo":"FuelLabs/fuels-ts","slug":"encode-error-f571dc","errorCode":"ENCODE_ERROR","errorMessage":"Types/values length mismatch.","messagePattern":"Types/values length mismatch\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/TupleCoder.ts","lineNumber":32,"sourceCode":"};\n\nexport class TupleCoder<TCoders extends Coder[]> extends Coder<\n  InputValueOf<TCoders>,\n  DecodedValueOf<TCoders>\n> {\n  coders: TCoders;\n  #hasNestedOption: boolean;\n\n  constructor(coders: TCoders) {\n    const encodedLength = coders.reduce((acc, coder) => acc + coder.encodedLength, 0);\n    super('tuple', `(${coders.map((coder) => coder.type).join(', ')})`, encodedLength);\n    this.coders = coders;\n    this.#hasNestedOption = hasNestedOption(coders);\n  }\n\n  encode(value: InputValueOf<TCoders>): Uint8Array {\n    if (this.coders.length !== value.length) {\n      throw new FuelError(ErrorCode.ENCODE_ERROR, `Types/values length mismatch.`);\n    }\n\n    return concatBytes(this.coders.map((coder, i) => coder.encode(value[i])));\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 tuple data size.`);\n    }\n\n    let newOffset = offset;\n    const decodedValue = this.coders.map((coder) => {\n      let decoded;\n      [decoded, newOffset] = coder.decode(data, newOffset);\n\n      return decoded;\n    });\n","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/TupleCoder.ts#L14-L50","documentation":"Thrown by TupleCoder.encode() when the number of values in the input array does not match the number of coders in the tuple type. A Sway tuple (A, B, C) expects exactly 3 values; providing fewer or more triggers this error. TupleCoder has a fixed arity defined at construction time.","triggerScenarios":"ABI declares tuple (u32, bool, b256) but the caller passes [42] or [42, true, addr, extra]. Constructing tuple values from variable-length data without enforcing arity. Forgetting one element when building the tuple value.","commonSituations":"ABI tuple type changed but client code not updated. Dynamic data with variable arity passed to a fixed-arity tuple coder. Misunderstanding of tuple vs array semantics.","solutions":["Match the value array length to the tuple's element count.","Update the client when the ABI tuple arity changes.","Use TypeScript tuple types ([A, B, C]) to enforce arity at compile time."],"exampleFix":"// before\nconst coder = new TupleCoder([new NumberCoder('u32'), new BooleanCoder()]);\ncoder.encode([1]); // throws ENCODE_ERROR, expected 2 values\n\n// after\ncoder.encode([1, true]);","handlingStrategy":"validation","validationCode":"function matchesTupleArity(values: unknown[], expectedLength: number): boolean {\n  return Array.isArray(values) && values.length === expectedLength;\n}","typeGuard":"function isTupleOfArity<T extends unknown[]>(value: unknown, arity: number): value is T {\n  return Array.isArray(value) && value.length === arity;\n}","tryCatchPattern":null,"preventionTips":["Use TypeScript tuple types ([A, B, C]) not arrays (A[]) for tuple values.","Validate arity against the ABI before encoding.","When the ABI tuple changes, regenerate client types."],"tags":["abi-coder","encoding","tuple","arity"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}