{"record":{"id":"abf4c3ebe7a909bf","repo":"FuelLabs/fuels-ts","slug":"decode-error-abf4c3","errorCode":"DECODE_ERROR","errorMessage":"Invalid string data size.","messagePattern":"Invalid string data size\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/StringCoder.ts","lineNumber":21,"sourceCode":"\nimport { Coder } from './AbstractCoder';\n\nexport class StringCoder<TLength extends number = number> extends Coder<string, string> {\n  constructor(length: TLength) {\n    super('string', `str[${length}]`, length);\n  }\n\n  encode(value: string): Uint8Array {\n    if (value.length !== this.encodedLength) {\n      throw new FuelError(ErrorCode.ENCODE_ERROR, `Value length mismatch during encode.`);\n    }\n\n    return toUtf8Bytes(value);\n  }\n\n  decode(data: Uint8Array, offset: number): [string, number] {\n    if (data.length < this.encodedLength) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string data size.`);\n    }\n\n    const bytes = data.slice(offset, offset + this.encodedLength);\n\n    if (bytes.length !== this.encodedLength) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string byte data size.`);\n    }\n\n    return [toUtf8String(bytes), offset + this.encodedLength];\n  }\n}\n","sourceCodeStart":3,"sourceCodeEnd":33,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/StringCoder.ts#L3-L33","documentation":"Thrown by StringCoder.decode() when the data buffer is shorter than the fixed length N declared by the coder. Unlike variable-length string coders, StringCoder expects exactly N bytes of data to decode a fixed-length Sway str[N].","triggerScenarios":"Decoding a buffer of 2 bytes when the coder expects str[10] (10 bytes). Truncated ABI payload. Using the wrong coder for the data format.","commonSituations":"ABI mismatch between encoder and decoder. Truncated network data. Wrong coder type used (fixed-length vs variable-length string).","solutions":["Verify data.length >= coder.encodedLength (N) before calling decode().","Confirm the coder's N matches the ABI's str[N] declaration.","Ensure data is not truncated in transit."],"exampleFix":"// before\nnew StringCoder(10).decode(new Uint8Array([65, 66]), 0); // throws DECODE_ERROR\n\n// after\nconst coder = new StringCoder(10);\nif (data.length < coder.encodedLength) {\n  throw new Error(`Need ${coder.encodedLength} bytes, got ${data.length}`);\n}\ncoder.decode(data, 0);","handlingStrategy":"validation","validationCode":"function canDecodeFixedString(data: Uint8Array, length: number): boolean {\n  return data.length >= length;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate buffer length against the ABI str[N] before decoding.","Ensure encoder and decoder use the same ABI.","Log coder.encodedLength on decode failures."],"tags":["abi-coder","decoding","string","data-validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}