Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: port errors to new system #19034

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ddc5532
zlib: port errors to new system
targos Feb 27, 2018
def3846
vm: port errors to new system
targos Feb 27, 2018
c0d20ba
v8: port errors to new system
targos Feb 27, 2018
b08cf46
util: port errors to new system
targos Feb 27, 2018
4a314e7
url: port errors to new system
targos Feb 27, 2018
247ddb8
tty: port errors to new system
targos Feb 27, 2018
870cdf0
tls: port: errors to new system
targos Feb 27, 2018
a7aa7bd
timers: port errors to new system
targos Feb 27, 2018
f350861
string_decoder: port errors to new system
targos Feb 27, 2018
82a4d20
repl: port errors to new system
targos Feb 27, 2018
fa70791
readline: port errors to new system
targos Feb 27, 2018
721314e
querystring: port errors to new system
targos Feb 27, 2018
a7df2bc
perf_hooks: port errors to new system
targos Feb 27, 2018
bda8874
path: port errors to new system
targos Feb 27, 2018
530f289
net: port errors to new system
targos Feb 27, 2018
ac2c9c3
module: port errors to new system
targos Feb 27, 2018
d102090
inspector: port errors to new system
targos Feb 27, 2018
0db60be
https: port errors to new system
targos Feb 27, 2018
a6b8a25
fs: port errors to new system
targos Feb 27, 2018
0b226fd
events: port errors to new system
targos Feb 27, 2018
ee6945c
domain: port errors to new system
targos Feb 27, 2018
5eaffd2
dns: port errors to new system
targos Feb 27, 2018
eabb4f6
dgram: port errors to new system
targos Feb 27, 2018
7d14db2
crypto: port errors to new system
targos Feb 27, 2018
e78c0f9
child_process: port errors to new system
targos Feb 27, 2018
bee022b
buffer: port errors to new system
targos Feb 27, 2018
eccd4b0
async_hooks: port errors to new system
targos Feb 27, 2018
dbddf7b
assert: port errors to new system
targos Feb 27, 2018
0d5b4b9
FIXUP: linter
targos Mar 4, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ const {
isDeepEqual,
isDeepStrictEqual
} = require('internal/util/comparisons');
const { AssertionError, TypeError, errorCache } = require('internal/errors');
const {
AssertionError,
errorCache,
codes: {
ERR_INVALID_ARG_TYPE
}
} = require('internal/errors');
const { openSync, closeSync, readSync } = require('fs');
const { parseExpressionAt } = require('internal/deps/acorn/dist/acorn');
const { inspect } = require('util');
Expand Down Expand Up @@ -380,8 +386,9 @@ function expectedException(actual, expected, msg) {
return expected.test(actual);
// assert.doesNotThrow does not accept objects.
if (arguments.length === 2) {
throw new TypeError('ERR_INVALID_ARG_TYPE', 'expected',
['Function', 'RegExp'], expected);
throw new ERR_INVALID_ARG_TYPE(
'expected', ['Function', 'RegExp'], expected
);
}
// The name and message could be non enumerable. Therefore test them
// explicitly.
Expand All @@ -408,8 +415,7 @@ function expectedException(actual, expected, msg) {

function getActual(block) {
if (typeof block !== 'function') {
throw new TypeError('ERR_INVALID_ARG_TYPE', 'block', 'Function',
block);
throw new ERR_INVALID_ARG_TYPE('block', 'Function', block);
}
try {
block();
Expand All @@ -425,10 +431,7 @@ assert.throws = function throws(block, error, message) {

if (typeof error === 'string') {
if (arguments.length === 3)
throw new TypeError('ERR_INVALID_ARG_TYPE',
'error',
['Function', 'RegExp'],
error);
throw new ERR_INVALID_ARG_TYPE('error', ['Function', 'RegExp'], error);

message = error;
error = null;
Expand Down
22 changes: 12 additions & 10 deletions lib/async_hooks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
'use strict';

const errors = require('internal/errors');
const {
ERR_ASYNC_CALLBACK,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ASYNC_ID
} = require('internal/errors').codes;
const async_wrap = process.binding('async_wrap');
const internal_async_hooks = require('internal/async_hooks');

Expand Down Expand Up @@ -41,15 +45,15 @@ const {
class AsyncHook {
constructor({ init, before, after, destroy, promiseResolve }) {
if (init !== undefined && typeof init !== 'function')
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.init');
throw new ERR_ASYNC_CALLBACK('hook.init');
if (before !== undefined && typeof before !== 'function')
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.before');
throw new ERR_ASYNC_CALLBACK('hook.before');
if (after !== undefined && typeof after !== 'function')
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.after');
throw new ERR_ASYNC_CALLBACK('hook.after');
if (destroy !== undefined && typeof destroy !== 'function')
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.destroy');
throw new ERR_ASYNC_CALLBACK('hook.destroy');
if (promiseResolve !== undefined && typeof promiseResolve !== 'function')
throw new errors.TypeError('ERR_ASYNC_CALLBACK', 'hook.promiseResolve');
throw new ERR_ASYNC_CALLBACK('hook.promiseResolve');

this[init_symbol] = init;
this[before_symbol] = before;
Expand Down Expand Up @@ -140,7 +144,7 @@ function showEmitBeforeAfterWarning() {
class AsyncResource {
constructor(type, opts = {}) {
if (typeof type !== 'string')
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'type', 'string');
throw new ERR_INVALID_ARG_TYPE('type', 'string');

if (typeof opts === 'number') {
opts = { triggerAsyncId: opts, requireManualDestroy: false };
Expand All @@ -152,9 +156,7 @@ class AsyncResource {
// triggerAsyncId.
const triggerAsyncId = opts.triggerAsyncId;
if (!Number.isSafeInteger(triggerAsyncId) || triggerAsyncId < -1) {
throw new errors.RangeError('ERR_INVALID_ASYNC_ID',
'triggerAsyncId',
triggerAsyncId);
throw new ERR_INVALID_ASYNC_ID('triggerAsyncId', triggerAsyncId);
}

this[async_id_symbol] = newAsyncId();
Expand Down
Loading