Hash update() called after digest() was already called
Production Risk
Low — caught immediately; create new Hash instances for each operation.
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.
- 1Calling hash.update() after hash.digest() has already been invoked
- 2Reusing a Hash object across multiple hashing operations
- 3Calling digest() and then update() in async code that runs out of order
Triggered when update() is called on a Hash object whose digest() has already been invoked.
const { createHash } = require('crypto');
const hash = createHash('sha256');
hash.update('part1');
const result = hash.digest('hex');
hash.update('part2'); // throws — digest already calledexpected 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
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.
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_FINALIZEDtry {
// 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
}
}const { createHash } = require('crypto')
function hashValue(data) {
return createHash('sha256').update(data).digest('hex') // fresh instance each call
}✕ Reuse a Hash object after calling digest()
Hash objects are stateful and one-time-use; digest() finalises them.
Node.js Error Codes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev