How to use verror

Comprehensive verror code examples:

How to use verror.call:

3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
var BCO = BufferCursor.BufferCursorOverflow = function(length, pos, size) {
  this.kind = 'BufferCursorOverflow';
  this.length = length;
  this.position = pos;
  this.size = size;
  VError.call(this,
              'BufferCursorOverflow: length %d, position %d, size %d',
              length,
              pos,
              size);

How to use verror.info:

11478
11479
11480
11481
11482
11483
11484
11485
11486
var rv, cause, k;

mod_assertplus.ok(mod_isError(err), 'err must be an Error');
cause = VError.cause(err);
if (cause !== null) {
	rv = VError.info(cause);
} else {
	rv = {};
}

How to use verror.fullStack:

11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
	mod_assertplus.ok(mod_isError(err), 'err must be an Error');


	var cause = VError.cause(err);


	if (cause) {
		return (err.stack + '\ncaused by: ' + VError.fullStack(cause));
	}


	return (err.stack);
};

How to use verror.cause:

132
133
134
135
136
137
138
139
140
141
    scope.setContext('payload.data', payload.data);
    delete payload.data;
  }
  scope.setContext('payload', payload);
}
const cause = verror.cause(err);
if (cause && cause.message) {
  const causeContext = {
    errorName: cause.name,
    reason: cause.reason,

How to use verror.WError:

240
241
242
243
244
245
246
247
248
249
  assert.strictEqual(error1, cause);
});

it('determines cause of nested WError', async () => {
  const error1 = new Error('BOOM');
  const error2 = new verror.WError(error1);
  const error3 = new verror.WError(error2);
  const cause = getRootCause(error3);
  assert.strictEqual(error1, cause);
});

How to use verror.VError:

554
555
556
557
558
559
560
561
562
563
564
565
			propname = propname + '.' + reason.substr(i, j - i);


		reason = 'unsupported property';
	}


	var rv = new mod_verror.VError('property "%s": %s', propname, reason);
	rv.jsv_details = error;
	return (rv);
}