{"record":{"id":"4e5cef0402a0cd2c","repo":"FuelLabs/fuels-ts","slug":"decode-error-4e5cef","errorCode":"DECODE_ERROR","errorMessage":"Invalid byte data size.","messagePattern":"Invalid byte data size\\.","errorType":"error_code","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/ByteCoder.ts","lineNumber":24,"sourceCode":"import { Coder } from './AbstractCoder';\nimport { BigNumberCoder } from './BigNumberCoder';\n\nexport class ByteCoder extends Coder<number[], Uint8Array> {\n  static memorySize = 1;\n  constructor() {\n    super('struct', 'struct Bytes', WORD_SIZE);\n  }\n\n  encode(value: number[] | Uint8Array): Uint8Array {\n    const bytes = value instanceof Uint8Array ? value : new Uint8Array(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): [Uint8Array, number] {\n    if (data.length < WORD_SIZE) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid byte 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\n    const dataBytes = data.slice(offsetAndLength, offsetAndLength + length);\n\n    if (dataBytes.length !== length) {\n      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid bytes byte data size.`);\n    }\n\n    return [dataBytes, offsetAndLength + length];\n  }\n}\n","sourceCodeStart":6,"sourceCodeEnd":40,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/ByteCoder.ts#L6-L40","documentation":"Thrown by ByteCoder.decode at the top guard: data.length < WORD_SIZE (8). The message is the literal \"Invalid byte data size.\". A Sway Bytes value is length-prefixed by a u64, so at least 8 bytes are needed just to read the length. Fewer than 8 bytes means the payload cannot contain the length header.","triggerScenarios":"Calling byteVec.decode(data, offset) with data shorter than 8 bytes, e.g. a truncated or empty payload, or a wrong offset leaving fewer than 8 bytes.","commonSituations":"Truncated Bytes return data from the provider; wrong coder applied to the bytes; manual offset advanced past the length header; decoding an empty/garbage buffer.","solutions":["Verify data.length >= WORD_SIZE (8) before decode.","Confirm the bytes actually represent a length-prefixed Sway Bytes value.","Let AbiCoder handle offset/prefix bookkeeping."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (data.length < 8) throw new Error('need >= 8 bytes for Bytes length header')\nbyteCoder.decode(data, offset)","typeGuard":"const canDecodeBytes = (data: Uint8Array) => data.length >= 8","tryCatchPattern":"try { byteCoder.decode(data, offset) }\ncatch (e) { if ((e as FuelError).code === ErrorCode.DECODE_ERROR) { /* payload too short / wrong coder */ } throw e }","preventionTips":["Ensure the buffer carries the u64 length prefix intact.","Use the framework decoder rather than manual slicing.","Validate at least WORD_SIZE bytes are present before decode."],"tags":["abi-coder","decoding","bytes","data-length"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}