Dev Helpers

Node.js / Assertions

Check an error-first callback result

Dev Helpers · January 16, 2026

Error-first callbacks carry failure and success through separate arguments. Centralizing the error check makes the success path easier to inspect.

Worked example

import assert from "node:assert/strict";
console.log((assert.ifError(null), "passed"));

Result

passed

Implementation notes

Returning immediately after handling an error prevents the success path from trying to use a missing result.

Try it yourself

Call the handler with an error and with a legitimate falsy result.

Open the Node.js example →

Editorial date January 16, 2026 · Published December 6, 2026

Related articles

Safely parse malformed input

Parsing user-provided JSON needs a failure path. Successful parsing alone does not establish that the result has the expected shape.

Checksum bytes with CRC32

CRC32 is useful for detecting accidental changes to a byte sequence. Record the input encoding so different producers compute the same checksum.

Attach details to a mark

Performance marks can carry details about the operation they describe. Small stable identifiers are easier to aggregate than large payloads.