{"record":{"id":"33ad57ddff7265da","repo":"FuelLabs/fuels-ts","slug":"decode-error-33ad57","errorCode":"DECODE_ERROR","errorMessage":"Invalid std string data size.","messagePattern":"Invalid std string data size\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/StdStringCoder.ts","lineNumber":25,"sourceCode":"import { Coder } from './AbstractCoder';\nimport { BigNumberCoder } from './BigNumberCoder';\n\nexport class StdStringCoder extends Coder<string, string> {\n  static memorySize = 1;\n  constructor() {\n    super('struct', 'struct String', WORD_SIZE);\n  }\n\n  encode(value: string): Uint8Array {\n    const bytes = toUtf8Bytes(value);\n    const lengthBytes = new BigNumberCoder('u64').encode(value.length);\n\n    return new Uint8Array([...lengthBytes, ...bytes]);\n  }\n\n  decode(data: Uint8Array, offset: number): [string, number] {\n    if (data.length < this.encodedLength) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string data size.`);\n    }\n\n    const offsetAndLength = offset + WORD_SIZE;\n    const lengthBytes = data.slice(offset, offsetAndLength);\n    const length = bn(new BigNumberCoder('u64').decode(lengthBytes, 0)[0]).toNumber();\n    const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);\n\n    if (dataBytes.length !== length) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);\n    }\n\n    return [toUtf8String(dataBytes), offsetAndLength + length];\n  }\n}\n","sourceCodeStart":7,"sourceCodeEnd":40,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/StdStringCoder.ts#L7-L40","documentation":"Thrown by StdStringCoder.decode() when the data buffer is shorter than WORD_SIZE (8 bytes). A Sway std::string::String is encoded as a u64 character-count prefix followed by UTF-8 bytes, so at least 8 bytes are required to read the length prefix alone.","triggerScenarios":"Passing fewer than 8 bytes to decode(). Decoding data that was not produced by StdStringCoder.encode(). Receiving a truncated ABI payload from an RPC response.","commonSituations":"Using the wrong coder for the data (e.g., StringCoder fixed-length vs StdStringCoder variable-length). Malformed data from chain. Buffer allocation or slicing errors upstream.","solutions":["Verify data.length >= 8 before calling decode().","Confirm you are using StdStringCoder (variable-length struct String) and not StringCoder (fixed-length str[N]).","Ensure the data originates from a compatible Sway ABI encoding."],"exampleFix":"// before\nstdStringCoder.decode(new Uint8Array([0, 0, 0]), 0); // throws DECODE_ERROR\n\n// after\nif (data.length < 8) {\n  throw new Error('Data too short for std String decode');\n}\nstdStringCoder.decode(data, 0);","handlingStrategy":"validation","validationCode":"function canDecodeStdString(data: Uint8Array): boolean {\n  return data.length >= 8; // WORD_SIZE\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Distinguish StdStringCoder (struct String, variable-length) from StringCoder (str[N], fixed-length).","Validate minimum buffer size before decoding.","Log the coder type and data length when debugging decode errors."],"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"}