mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
lib: port errors to new system
This is a first batch of updates that touches non-underscored modules in lib. PR-URL: https://github.com/nodejs/node/pull/19034 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
parent
023f49c5a9
commit
1e8d110e64
31 changed files with 377 additions and 418 deletions
|
@ -1,12 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const errors = require('internal/errors');
|
||||
const {
|
||||
ERR_INSPECTOR_ALREADY_CONNECTED,
|
||||
ERR_INSPECTOR_CLOSED,
|
||||
ERR_INSPECTOR_NOT_AVAILABLE,
|
||||
ERR_INSPECTOR_NOT_CONNECTED,
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_INVALID_CALLBACK
|
||||
} = require('internal/errors').codes;
|
||||
const util = require('util');
|
||||
const { Connection, open, url } = process.binding('inspector');
|
||||
|
||||
if (!Connection)
|
||||
throw new errors.Error('ERR_INSPECTOR_NOT_AVAILABLE');
|
||||
throw new ERR_INSPECTOR_NOT_AVAILABLE();
|
||||
|
||||
const connectionSymbol = Symbol('connectionProperty');
|
||||
const messageCallbacksSymbol = Symbol('messageCallbacks');
|
||||
|
@ -23,7 +30,7 @@ class Session extends EventEmitter {
|
|||
|
||||
connect() {
|
||||
if (this[connectionSymbol])
|
||||
throw new errors.Error('ERR_INSPECTOR_ALREADY_CONNECTED');
|
||||
throw new ERR_INSPECTOR_ALREADY_CONNECTED();
|
||||
this[connectionSymbol] =
|
||||
new Connection((message) => this[onMessageSymbol](message));
|
||||
}
|
||||
|
@ -47,23 +54,21 @@ class Session extends EventEmitter {
|
|||
|
||||
post(method, params, callback) {
|
||||
if (typeof method !== 'string') {
|
||||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
|
||||
'method', 'string', method);
|
||||
throw new ERR_INVALID_ARG_TYPE('method', 'string', method);
|
||||
}
|
||||
if (!callback && util.isFunction(params)) {
|
||||
callback = params;
|
||||
params = null;
|
||||
}
|
||||
if (params && typeof params !== 'object') {
|
||||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
|
||||
'params', 'Object', params);
|
||||
throw new ERR_INVALID_ARG_TYPE('params', 'Object', params);
|
||||
}
|
||||
if (callback && typeof callback !== 'function') {
|
||||
throw new errors.TypeError('ERR_INVALID_CALLBACK');
|
||||
throw new ERR_INVALID_CALLBACK();
|
||||
}
|
||||
|
||||
if (!this[connectionSymbol]) {
|
||||
throw new errors.Error('ERR_INSPECTOR_NOT_CONNECTED');
|
||||
throw new ERR_INSPECTOR_NOT_CONNECTED();
|
||||
}
|
||||
const id = this[nextIdSymbol]++;
|
||||
const message = { id, method };
|
||||
|
@ -83,7 +88,7 @@ class Session extends EventEmitter {
|
|||
this[connectionSymbol] = null;
|
||||
const remainingCallbacks = this[messageCallbacksSymbol].values();
|
||||
for (const callback of remainingCallbacks) {
|
||||
process.nextTick(callback, new errors.Error('ERR_INSPECTOR_CLOSED'));
|
||||
process.nextTick(callback, new ERR_INSPECTOR_CLOSED());
|
||||
}
|
||||
this[messageCallbacksSymbol].clear();
|
||||
this[nextIdSymbol] = 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue