{"record":{"id":"3ce87c67a381db6b","repo":"FuelLabs/fuels-ts","slug":"decode-error-3ce87c","errorCode":"DECODE_ERROR","errorMessage":"Invalid raw slice data size.","messagePattern":"Invalid raw slice data size\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/RawSliceCoder.ts","lineNumber":30,"sourceCode":"  constructor() {\n    super('raw untyped slice', 'raw untyped slice', WORD_SIZE);\n  }\n\n  encode(value: number[]): Uint8Array {\n    if (!Array.isArray(value)) {\n      throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);\n    }\n\n    const internalCoder = new ArrayCoder(new NumberCoder('u8'), value.length);\n    const bytes = internalCoder.encode(value);\n    const lengthBytes = new BigNumberCoder('u64').encode(bytes.length);\n\n    return new Uint8Array([...lengthBytes, ...bytes]);\n  }\n\n  decode(data: Uint8Array, offset: number): [number[], number] {\n    if (data.length < this.encodedLength) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw 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 dataBytes = data.slice(offsetAndLength, offsetAndLength + length);\n\n    if (dataBytes.length !== length) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid raw slice byte data size.`);\n    }\n\n    const internalCoder = new ArrayCoder(new NumberCoder('u8'), length);\n    const [decodedValue] = internalCoder.decode(dataBytes, 0);\n\n    return [decodedValue, offsetAndLength + length];\n  }\n}\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/RawSliceCoder.ts#L12-L48","documentation":"Thrown by RawSliceCoder.decode() when the data buffer is shorter than WORD_SIZE (8 bytes). The raw slice encoding begins with an 8-byte u64 big-endian length prefix, so any payload smaller than 8 bytes cannot contain even the length header.","triggerScenarios":"Passing a byte array with fewer than 8 bytes to decode(). Receiving a truncated or empty ABI-encoded raw slice from an RPC call. Using the wrong coder for the data format.","commonSituations":"Malformed RPC response data. Buffer truncation during network transmission. ABI version mismatch producing differently sized payloads.","solutions":["Verify data.length >= 8 (WORD_SIZE) before calling decode().","Ensure the data was produced by a compatible encoder or Sway ABI.","Check for ABI mismatches if data consistently fails this check."],"exampleFix":"// before\nrawSliceCoder.decode(new Uint8Array([1, 2, 3]), 0); // throws DECODE_ERROR\n\n// after\nconst WORD_SIZE = 8;\nif (data.length < WORD_SIZE) {\n  throw new Error('Data too short for raw slice decode');\n}\nrawSliceCoder.decode(data, 0);","handlingStrategy":"validation","validationCode":"const WORD_SIZE = 8;\nfunction canDecodeRawSlice(data: Uint8Array): boolean {\n  return data.length >= WORD_SIZE;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate minimum buffer size (8 bytes) before decoding variable-length types.","Log data.length on decode failures to identify truncation.","Use the same ABI version on both sides of the encoding boundary."],"tags":["abi-coder","decoding","raw-slice","data-validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}