{"record":{"id":"b51a4b9bd9b22363","repo":"FuelLabs/fuels-ts","slug":"encode-error-b51a4b","errorCode":"ENCODE_ERROR","errorMessage":"Expected array value.","messagePattern":"Expected array value\\.","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/RawSliceCoder.ts","lineNumber":18,"sourceCode":"import { ErrorCode, FuelError } from '@fuel-ts/errors';\nimport { bn } from '@fuel-ts/math';\n\nimport { WORD_SIZE } from '../../utils/constants';\n\nimport { Coder } from './AbstractCoder';\nimport { ArrayCoder } from './ArrayCoder';\nimport { BigNumberCoder } from './BigNumberCoder';\nimport { NumberCoder } from './NumberCoder';\n\nexport class RawSliceCoder extends Coder<number[], number[]> {\n  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);","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/RawSliceCoder.ts#L1-L36","documentation":"Thrown by RawSliceCoder.encode() when the input is not a JavaScript array. RawSliceCoder encodes Sway raw untyped slices and expects a number[] (array of byte values 0-255). Passing any non-array value, including a string, number, object, or even a Uint8Array, triggers this error because Uint8Array fails Array.isArray().","triggerScenarios":"Calling encode('hello') (string instead of char codes), encode(42), or encode(new Uint8Array([...])). Note that Uint8Array is not accepted by RawSliceCoder even though it looks array-like. Passing a BN or object also fails.","commonSituations":"Confusing RawSliceCoder (number[]) with VecCoder (which does accept Uint8Array). Passing a hex string instead of a byte array. Deserializing data from JSON as an object rather than an array.","solutions":["Convert the value to number[] before encoding: Array.from(uint8Array) or split a string into char codes.","If you have a Uint8Array, use Array.from() to convert, or use VecCoder/BytesCoder which accepts Uint8Array directly.","Ensure each element is an integer in the 0-255 range."],"exampleFix":"// before\nrawSliceCoder.encode('abc');               // throws ENCODE_ERROR\nrawSliceCoder.encode(new Uint8Array([97]));  // throws ENCODE_ERROR\n\n// after\nrawSliceCoder.encode([97, 98, 99]);\nrawSliceCoder.encode(Array.from(uint8Array));","handlingStrategy":"type-guard","validationCode":"function isRawSliceValue(value: unknown): boolean {\n  return Array.isArray(value) && value.every(v => typeof v === 'number' && v >= 0 && v <= 255 && Number.isInteger(v));\n}","typeGuard":"function isRawSliceInput(value: unknown): value is number[] {\n  return Array.isArray(value) && value.every(v => typeof v === 'number' && Number.isInteger(v) && v >= 0 && v <= 255);\n}","tryCatchPattern":null,"preventionTips":["Distinguish RawSliceCoder (number[]) from VecCoder (number[] or Uint8Array).","Use Array.from() to convert typed arrays before passing to RawSliceCoder.","Validate that each byte is an integer in the 0-255 range."],"tags":["abi-coder","encoding","raw-slice","type-guard"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}