{"id":"868628877e5bae83","repo":"sindresorhus/is","slug":"expected-value-which-is-buffer-received-value-o","errorCode":null,"errorMessage":"Expected value which is `Buffer`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `Buffer`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1526,"sourceCode":"export function assertBoolean(value: unknown, message?: string): asserts value is boolean {\n\tif (!isBoolean(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('boolean', value));\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nexport function assertBoundFunction(value: unknown, message?: string): asserts value is Function {\n\tif (!isBoundFunction(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('bound Function', value));\n\t}\n}\n\n/**\nNote: [Prefer using `Uint8Array` instead of `Buffer`.](https://sindresorhus.com/blog/goodbye-nodejs-buffer)\n*/\nexport function assertBuffer(value: unknown, message?: string): asserts value is NodeBuffer {\n\tif (!isBuffer(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Buffer', value));\n\t}\n}\n\nexport function assertClass<T>(value: unknown, message?: string): asserts value is Class<T> {\n\tif (!isClass(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Class', value));\n\t}\n}\n\nexport function assertDataView(value: unknown, message?: string): asserts value is DataView {\n\tif (!isDataView(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('DataView', value));\n\t}\n}\n\nexport function assertDate(value: unknown, message?: string): asserts value is Date {\n\tif (!isDate(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('Date', value));","sourceCodeStart":1508,"sourceCodeEnd":1544,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1508-L1544","documentation":"Thrown by `assertBuffer()` when the value fails `isBuffer` (checks `value?.constructor?.isBuffer?.(value)`). It guards code that relies on Node Buffer-specific APIs. The library itself notes Buffer is legacy — prefer Uint8Array (see the JSDoc link at source/index.ts:1522).","triggerScenarios":"Calling `assert.buffer(value)` with a Uint8Array, ArrayBuffer, string, Blob, or in a browser/edge runtime where `Buffer` doesn't exist so nothing can pass.","commonSituations":"Code moved from Node to browsers, Deno, Cloudflare Workers, or Vite-bundled frontends where Buffer is absent or shimmed; `fetch().arrayBuffer()` results passed where a Buffer was expected; libraries returning Uint8Array after migrating off Buffer (a common modern API change).","solutions":["Convert before asserting: `Buffer.from(uint8ArrayOrArrayBuffer)`.","Preferably migrate the code to accept Uint8Array (`assert.uint8Array`) instead of Buffer, per the library's own guidance.","In non-Node runtimes, remove the Buffer requirement or add an explicit Buffer polyfill only if truly needed.","Check whether a dependency upgrade changed its return type from Buffer to Uint8Array and adapt."],"exampleFix":"// before\nassert.buffer(await response.arrayBuffer());\n// after\nassert.buffer(Buffer.from(await response.arrayBuffer()));\n// or better, per library guidance:\nassert.uint8Array(new Uint8Array(await response.arrayBuffer()));","handlingStrategy":"type-guard","validationCode":"if (!Buffer.isBuffer(value)) {\n  value = Buffer.from(value); // explicit conversion from string/Uint8Array\n}","typeGuard":"function isBuffer(value: unknown): value is Buffer {\n  return typeof Buffer !== 'undefined' && Buffer.isBuffer(value);\n}","tryCatchPattern":"try {\n  assert.buffer(value);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // Uint8Array or string received — convert with Buffer.from() or fix the producer\n  } else throw error;\n}","preventionTips":["Use Buffer.isBuffer(), not instanceof, so cross-realm buffers are handled","Buffer is Node-only — in browser/edge runtimes prefer Uint8Array APIs or a polyfill, and know which one your bundler injects","A Uint8Array is not a Buffer even though Buffer extends it — convert with Buffer.from(uint8) (zero-copy via its buffer if needed)"],"tags":["type-assertion","node","buffer","uint8array","cross-platform"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}