{"record":{"id":"c19a30b7f9ac51ef","repo":"denoland/deno","slug":"err-invalid-arg-type-c19a30","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"data\" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received ${data}","messagePattern":"The \"data\" argument must be of type string or an instance of Buffer, TypedArray, or DataView\\. Received (.+?)","errorType":"exception","errorClass":"ERR_INVALID_ARG_TYPE","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/crypto/hash.ts","lineNumber":189,"sourceCode":"};\n\nHash.prototype._flush = function _flush(callback: () => void) {\n  const digest = op_node_hash_digest(this[kHandle]);\n  // deno-lint-ignore deno-internal/prefer-primordials -- `this` is a Node stream (Transform)\n  this.push(digest === null ? Buffer.alloc(0) : Buffer.from(digest));\n  callback();\n};\n\nHash.prototype.update = function update(\n  data: string | Buffer,\n  encoding: any,\n) {\n  encoding = encoding || getDefaultEncoding();\n\n  if (typeof data === \"string\") {\n    validateEncoding(data, encoding);\n  } else if (!isArrayBufferView(data)) {\n    throw new ERR_INVALID_ARG_TYPE(\n      \"data\",\n      [\"string\", \"Buffer\", \"TypedArray\", \"DataView\"],\n      data,\n    );\n  }\n\n  if (\n    typeof data === \"string\" && (encoding === \"utf8\" || encoding === \"buffer\")\n  ) {\n    unwrapErr(op_node_hash_update_str(this[kHandle], data));\n  } else {\n    const buf = toBuf(data as string | Buffer, encoding);\n    const u8 = ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, buf)\n      ? buf as Uint8Array\n      : new Uint8Array(\n        // deno-lint-ignore deno-internal/prefer-primordials -- ArrayBufferView accessor, receiver may be a DataView\n        (buf as ArrayBufferView).buffer,\n        // deno-lint-ignore deno-internal/prefer-primordials -- ArrayBufferView accessor, receiver may be a DataView","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/crypto/hash.ts#L171-L207","documentation":"Hash.update() accepts only strings and ArrayBuffer views (Buffer, TypedArray, DataView); any other value — number, null, plain object, BigInt — throws ERR_INVALID_ARG_TYPE for 'data'. Strings are additionally checked against the requested encoding before being fed to the native op.","triggerScenarios":"h.update(123), h.update(null), h.update(BigInt(42)), or h.update(someObject) where a serialization step was forgotten (e.g. passing JSON.stringify instead of JSON.stringify(x) — a function reference).","commonSituations":"Feeding numeric IDs or counters directly into an HMAC; null creeping in from optional fields; forgetting to call a value-producing function; passing a Node Buffer from a different realm/monkey-patched environment that fails the view check.","solutions":["Convert non-string inputs to Buffer first: h.update(Buffer.from(String(id))) or h.update(Uint8Array)","Null-check optional fields before updating and skip or substitute an empty string","Verify function calls actually happened: JSON.stringify(payload), not JSON.stringify"],"exampleFix":"// before\nh.update(user.id); // number\n\n// after\nh.update(String(user.id));","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"const isHashData = (v: unknown): v is string | Buffer | Uint8Array | DataView =>\n  typeof v === 'string' || ArrayBuffer.isView(v);","tryCatchPattern":null,"preventionTips":["Coerce IDs/numbers with String() before updating","Null-check optional fields and skip or use '' when absent","In TypeScript, type the update() parameter as string | Buffer | Uint8Array"],"tags":["crypto","hash","argument-validation","node-compat"],"backgroundTag":"invalid-argument-type","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-21T08:17:14.275Z"}