-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
errors: add support for cause in aborterror
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #41008 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
- Loading branch information
Showing
2 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
require('../common'); | ||
const { | ||
strictEqual, | ||
throws, | ||
} = require('assert'); | ||
const { AbortError } = require('internal/errors'); | ||
|
||
{ | ||
const err = new AbortError(); | ||
strictEqual(err.message, 'The operation was aborted'); | ||
strictEqual(err.cause, undefined); | ||
} | ||
|
||
{ | ||
const cause = new Error('boom'); | ||
const err = new AbortError('bang', { cause }); | ||
strictEqual(err.message, 'bang'); | ||
strictEqual(err.cause, cause); | ||
} | ||
|
||
{ | ||
throws(() => new AbortError('', false), { | ||
code: 'ERR_INVALID_ARG_TYPE' | ||
}); | ||
throws(() => new AbortError('', ''), { | ||
code: 'ERR_INVALID_ARG_TYPE' | ||
}); | ||
} |