ERR_CRYPTO_HASH_FINALIZED
Node.jsERRORNotableCryptoHIGH confidence

Hash update() called after digest() was already called

Production Risk

Low — caught immediately; create new Hash instances for each operation.

What this means

Thrown when hash.update() is called on a Hash object after hash.digest() has already been called. Once digest() is called, the hash is finalised and its internal state is reset or destroyed; calling update() again is not valid.

Why it happens
  1. 1Calling hash.update() after hash.digest() has already been invoked
  2. 2Reusing a Hash object across multiple hashing operations
  3. 3Calling digest() and then update() in async code that runs out of order
How to reproduce

Triggered when update() is called on a Hash object whose digest() has already been invoked.

trigger — this will error
trigger — this will error
const { createHash } = require('crypto');
const hash = createHash('sha256');
hash.update('part1');
const result = hash.digest('hex');
hash.update('part2'); // throws — digest already called

expected output

Error [ERR_CRYPTO_HASH_FINALIZED]: Digest already called

Fix

Create a new Hash object for each hashing operation

WHEN When hashing multiple independent values

Create a new Hash object for each hashing operation
const { createHash } = require('crypto');
function hashValue(data) {
  return createHash('sha256').update(data).digest('hex');
}
const h1 = hashValue('part1');
const h2 = hashValue('part2');

Why this works

Each createHash() call produces a fresh Hash object; calling digest() on one does not affect others.

Code examples
Triggerjs
const { createHash } = require('crypto');
const hash = createHash('sha256');
hash.update('part1');
const result = hash.digest('hex');
hash.update('part2'); // throws — digest already called  // this triggers ERR_CRYPTO_HASH_FINALIZED
Handle in try/catchjs
try {
  // operation that may throw ERR_CRYPTO_HASH_FINALIZED
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_CRYPTO_HASH_FINALIZED') {
    console.error('ERR_CRYPTO_HASH_FINALIZED:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
const { createHash } = require('crypto')
function hashValue(data) {
  return createHash('sha256').update(data).digest('hex')  // fresh instance each call
}
What not to do

Reuse a Hash object after calling digest()

Hash objects are stateful and one-time-use; digest() finalises them.

Same error in other languages
Sources
Official documentation ↗

Node.js Error Codes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors