{"record":{"id":"94d15ab40ef1828a","repo":"FuelLabs/fuels-ts","slug":"decode-error-94d15a","errorCode":"DECODE_ERROR","errorMessage":"Invalid string slice data size.","messagePattern":"Invalid string slice data size\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/StrSliceCoder.ts","lineNumber":25,"sourceCode":"import { Coder } from './AbstractCoder';\nimport { BigNumberCoder } from './BigNumberCoder';\n\nexport class StrSliceCoder extends Coder<string, string> {\n  static memorySize = 1;\n  constructor() {\n    super('strSlice', 'str', 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 string slice 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 bytes = data.slice(offsetAndLength, offsetAndLength + length);\n\n    if (bytes.length !== length) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice byte data size.`);\n    }\n\n    return [toUtf8String(bytes), offsetAndLength + length];\n  }\n}\n","sourceCodeStart":7,"sourceCodeEnd":40,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/StrSliceCoder.ts#L7-L40","documentation":"Thrown by StrSliceCoder.decode() when the data buffer is shorter than WORD_SIZE (8 bytes). A Sway str slice is encoded as a u64 length prefix followed by UTF-8 bytes, requiring at least 8 bytes for the length prefix.","triggerScenarios":"Passing fewer than 8 bytes to decode(). Decoding data not produced by StrSliceCoder. Receiving a truncated ABI payload from an RPC response.","commonSituations":"Confusing str slice (str) with std String (StdStringCoder) or fixed str[N] (StringCoder). Malformed RPC data. Buffer truncation in transit.","solutions":["Verify data.length >= 8 before calling decode().","Confirm the data is a str slice encoding, not a std String or fixed-length str[N].","Re-fetch data if truncation is suspected."],"exampleFix":"// before\nstrSliceCoder.decode(new Uint8Array([0]), 0); // throws DECODE_ERROR\n\n// after\nif (data.length < 8) {\n  throw new Error('Data too short for str slice decode');\n}\nstrSliceCoder.decode(data, 0);","handlingStrategy":"validation","validationCode":"function canDecodeStrSlice(data: Uint8Array): boolean {\n  return data.length >= 8; // WORD_SIZE\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Know the difference: str slice (StrSliceCoder), std String (StdStringCoder), fixed str[N] (StringCoder).","Validate buffer size before decoding variable-length string types.","Log the Sway type string when debugging decode failures."],"tags":["abi-coder","decoding","str-slice","data-validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}