value{any}
如果 value 不为 undefined 或 null,则抛出 value。
在回调中测试 error 参数时,这很有用。
堆栈跟踪包含传递给 ifError() 的错误的所有帧,包括 ifError() 本身的潜在新帧。
const assert = require('assert').strict;assert.ifError(null);// 通过。assert.ifError(0);// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0assert.ifError('错误');// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: '错误'assert.ifError(new Error());// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error// 创建一些随机错误帧。let err;(function errorFrame() {err = new Error('测试错误');})();(function ifErrorFrame() {assert.ifError(err);})();// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 测试错误// at ifErrorFrame// at errorFrame
