Throws value if value is not undefined or null. This is useful when testing the error argument in callbacks. The stack trace contains all frames from the error passed to ifError() including the potential new frames for ifError() itself.
value
undefined
null
error
ifError()
import assert from 'node:assert/strict';assert.ifError(null);// OKassert.ifError(0);// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0assert.ifError('error');// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 'error'assert.ifError(new Error());// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error// Create some random error frames.let err;(function errorFrame() { err = new Error('test error');})();(function ifErrorFrame() { assert.ifError(err);})();// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error// at ifErrorFrame// at errorFrame Copy
import assert from 'node:assert/strict';assert.ifError(null);// OKassert.ifError(0);// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0assert.ifError('error');// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 'error'assert.ifError(new Error());// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error// Create some random error frames.let err;(function errorFrame() { err = new Error('test error');})();(function ifErrorFrame() { assert.ifError(err);})();// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error// at ifErrorFrame// at errorFrame
v0.1.97
Throws
valueifvalueis notundefinedornull. This is useful when testing theerrorargument in callbacks. The stack trace contains all frames from the error passed toifError()including the potential new frames forifError()itself.