{"record":{"id":"da938ceb11dd040f","repo":"FuelLabs/fuels-ts","slug":"invalid-decode-value","errorCode":"INVALID_DECODE_VALUE","errorMessage":"A field for the case must be provided.","messagePattern":"A field for the case must be provided\\.","errorType":"error_code","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/EnumCoder.ts","lineNumber":65,"sourceCode":"  }\n\n  #encodeNativeEnum(value: string): Uint8Array {\n    const valueCoder = this.coders[value];\n    const encodedValue = valueCoder.encode([]);\n    const caseIndex = Object.keys(this.coders).indexOf(value);\n\n    const padding = new Uint8Array(this.#encodedValueSize - valueCoder.encodedLength);\n    return concat([this.#caseIndexCoder.encode(caseIndex), padding, encodedValue]);\n  }\n\n  encode(value: InputValueOf<TCoders>): Uint8Array {\n    if (typeof value === 'string' && this.coders[value]) {\n      return this.#encodeNativeEnum(value);\n    }\n\n    const [caseKey, ...empty] = Object.keys(value);\n    if (!caseKey) {\n      throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, 'A field for the case must be provided.');\n    }\n    if (empty.length !== 0) {\n      throw new FuelError(ErrorCode.INVALID_DECODE_VALUE, 'Only one field must be provided.');\n    }\n    const valueCoder = this.coders[caseKey];\n    const caseIndex = Object.keys(this.coders).indexOf(caseKey);\n    if (caseIndex === -1) {\n      const validCases = Object.keys(this.coders)\n        .map((v) => `'${v}'`)\n        .join(', ');\n      throw new FuelError(\n        ErrorCode.INVALID_DECODE_VALUE,\n        `Invalid case '${caseKey}'. Valid cases: ${validCases}.`\n      );\n    }\n\n    const encodedValue = valueCoder.encode(value[caseKey]);\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/EnumCoder.ts#L47-L83","documentation":"Thrown by EnumCoder.encode when Object.keys(value) is empty — i.e. the enum value object has no variant field set. The message is the literal \"A field for the case must be provided.\". A Sway enum value must specify exactly one case, so an empty object {} is rejected. Note the code is INVALID_DECODE_VALUE even though it fires during encode (a known misnomer in the library).","triggerScenarios":"Calling enumCoder.encode({}) or passing an empty object as a Sway enum argument; building an enum input programmatically that ends up with no keys; a default/initialized-to-empty value reaching the coder.","commonSituations":"Form/UI state where no enum option was selected; default parameter objects; spread/merge logic that removed all keys; JSON input that omitted the variant.","solutions":["Always set exactly one variant key on the enum value object.","Validate that Object.keys(value).length === 1 before encode.","Default to a meaningful variant instead of {} when none is chosen."],"exampleFix":"// before\nenumCoder.encode({}) // no case selected\n\n// after\nenumCoder.encode({ State: [] }) // exactly one variant","handlingStrategy":"validation","validationCode":"const keys = Object.keys(enumValue)\nif (keys.length !== 1) throw new Error('enum value must have exactly one variant key')\nenumCoder.encode(enumValue)","typeGuard":"const hasExactlyOneKey = (v: object): boolean => Object.keys(v).length === 1","tryCatchPattern":"try { enumCoder.encode(value as any) }\ncatch (e) { if ((e as FuelError).code === ErrorCode.INVALID_DECODE_VALUE) { /* set exactly one variant */ } throw e }","preventionTips":["Never pass {} as an enum value; default to a real variant.","Validate exactly-one-key before encoding.","Build enum inputs from explicit variant literals."],"tags":["abi-coder","encoding","enum","validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}