{"record":{"id":"e0f3767ea347deb0","repo":"amark/gun","slug":"first-argument-must-be-array-containing-arraybuffe","errorCode":null,"errorMessage":"First argument must be Array containing ArrayBuffer or Uint8Array instances.","messagePattern":"First argument must be Array containing ArrayBuffer or Uint8Array instances\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sea/buffer.js","lineNumber":71,"sourceCode":"          let buf\n          if (input instanceof ArrayBuffer) {\n            buf = new Uint8Array(input)\n          }\n          return SeaArray.from(buf || input)\n        }\n      },\n      // This is 'safe-buffer.alloc' sans encoding support\n      alloc(length, fill = 0 /*, enc*/ ) {\n        return SeaArray.from(new Uint8Array(Array.from({ length: length }, () => fill)))\n      },\n      // This is normal UNSAFE 'buffer.alloc' or 'new Buffer(length)' - don't use!\n      allocUnsafe(length) {\n        return SeaArray.from(new Uint8Array(Array.from({ length : length })))\n      },\n      // This puts together array of array like members\n      concat(arr) { // octet array\n        if (!Array.isArray(arr)) {\n          throw new TypeError('First argument must be Array containing ArrayBuffer or Uint8Array instances.')\n        }\n        return SeaArray.from(arr.reduce((ret, item) => ret.concat(Array.from(item)), []))\n      }\n    })\n    SafeBuffer.prototype.from = SafeBuffer.from\n    SafeBuffer.prototype.toString = SeaArray.prototype.toString\n\n    module.exports = SafeBuffer;\n  \n}());","sourceCodeStart":53,"sourceCodeEnd":81,"githubUrl":"https://github.com/amark/gun/blob/552227599d47ba0493824b7fcf8a00c8cd6404ba/sea/buffer.js#L53-L81","documentation":"SafeBuffer.concat joins an array of buffer-like items into one SeaArray. It first asserts the argument is a real Array (Array.isArray) and throws a TypeError otherwise — a non-array argument (single buffer, object, string) cannot be reduced item by item.","triggerScenarios":"Calling SafeBuffer.concat(buf) passing a single Uint8Array/SeaArray instead of wrapping it in an array; passing a plain object, arguments object, or iterable that is not an Array; passing an undefined variable. Note the error text mentions ArrayBuffer/Uint8Array contents, but the actual runtime check is only Array.isArray(arr).","commonSituations":"Translating Node Buffer.concat usage where someone forgot the array literal around a single buffer; spreading mistakes (forgetting the ... before a list of buffers); TypedArray subclass results (e.g. from subarray) that are not Array instances.","solutions":["Wrap the value in an array: SafeBuffer.concat([buf]) instead of SafeBuffer.concat(buf)","Ensure the argument is created as a real Array (array literal, Array.from(iterable)) — a TypedArray alone is not Array.isArray-true","Spread iterables: SafeBuffer.concat(Array.from(items))","Check for undefined/null sources upstream before calling concat"],"exampleFix":"// before\nconst joined = SafeBuffer.concat(part1).concat(part2);\n// after\nconst joined = SafeBuffer.concat([part1, part2]);","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(parts)) {\n  throw new TypeError('concat expects an array of buffer-like items');\n}","typeGuard":"const isBufList = (v) => Array.isArray(v) && v.every((x) => x && typeof x.length === 'number');","tryCatchPattern":"try {\n  const joined = SafeBuffer.concat(list);\n} catch (e) {\n  if (e instanceof TypeError) console.error('concat requires an array, got:', typeof list);\n  throw e;\n}","preventionTips":["Always pass an array literal: concat([buf]) even for one buffer","Convert iterables/TypedArrays with Array.from first","Remember the runtime check is Array.isArray, not content type"],"tags":["buffer","typeerror","array","sea"],"backgroundTag":"invalid-buffer-input","analyzedSha":"552227599d47ba0493824b7fcf8a00c8cd6404ba","analyzedAt":"2026-09-02T18:40:58.370Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}