| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -885,6 +885,31 @@ Used when `http2.connect()` is passed a URL that uses any protocol other than | |||
| 885 | 885 | ||
| 886 | 886 | Used when a given index is out of the accepted range (e.g. negative offsets). | |
| 887 | 887 | ||
| 888 | + <a id="ERR_INSPECTOR_ALREADY_CONNECTED"></a> | ||
| 889 | + ### ERR_INSPECTOR_ALREADY_CONNECTED | ||
| 890 | + | ||
| 891 | + When using the `inspector` module, the `ERR_INSPECTOR_ALREADY_CONNECTED` error | ||
| 892 | + code is used when an attempt is made to connect when the inspector is already | ||
| 893 | + connected. | ||
| 894 | + | ||
| 895 | + <a id="ERR_INSPECTOR_CLOSED"></a> | ||
| 896 | + ### ERR_INSPECTOR_CLOSED | ||
| 897 | + | ||
| 898 | + When using the `inspector` module, the `ERR_INSPECTOR_CLOSED` error code is | ||
| 899 | + used when an attempt is made to use the inspector after the session has | ||
| 900 | + already closed. | ||
| 901 | + | ||
| 902 | + <a id="ERR_INSPECTOR_NOT_AVAILABLE"></a> | ||
| 903 | + ### ERR_INSPECTOR_NOT_AVAILABLE | ||
| 904 | + | ||
| 905 | + Used to identify when the `inspector` module is not available for use. | ||
| 906 | + | ||
| 907 | + <a id="ERR_INSPECTOR_NOT_CONNECTED"></a> | ||
| 908 | + ### ERR_INSPECTOR_NOT_CONNECTED | ||
| 909 | + | ||
| 910 | + When using the `inspector` module, the `ERR_INSPECTOR_NOT_CONNECTED` error code | ||
| 911 | + is used when an attempt is made to use the inspector before it is connected. | ||
| 912 | + | ||
| 888 | 913 | <a id="ERR_INVALID_ARG_TYPE"></a> | |
| 889 | 914 | ### ERR_INVALID_ARG_TYPE | |
| 890 | 915 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,12 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const EventEmitter = require('events'); | |
| 4 | + const errors = require('internal/errors'); | ||
| 4 | 5 | const util = require('util'); | |
| 5 | 6 | const { Connection, open, url } = process.binding('inspector'); | |
| 6 | 7 | ||
| 7 | 8 | if (!Connection) | |
| 8 | - throw new Error('Inspector is not available'); | ||
| 9 | + throw new errors.Error('ERR_INSPECTOR_NOT_AVAILABLE'); | ||
| 9 | 10 | ||
| 10 | 11 | const connectionSymbol = Symbol('connectionProperty'); | |
| 11 | 12 | const messageCallbacksSymbol = Symbol('messageCallbacks'); | |
@@ -22,7 +23,7 @@ class Session extends EventEmitter { | |||
| 22 | 23 | ||
| 23 | 24 | connect() { | |
| 24 | 25 | if (this[connectionSymbol]) | |
| 25 | - throw new Error('Already connected'); | ||
| 26 | + throw new errors.Error('ERR_INSPECTOR_ALREADY_CONNECTED'); | ||
| 26 | 27 | this[connectionSymbol] = | |
| 27 | 28 | new Connection((message) => this[onMessageSymbol](message)); | |
| 28 | 29 | } | |
@@ -46,24 +47,23 @@ class Session extends EventEmitter { | |||
| 46 | 47 | ||
| 47 | 48 | post(method, params, callback) { | |
| 48 | 49 | if (typeof method !== 'string') { | |
| 49 | - throw new TypeError( | ||
| 50 | - `"method" must be a string, got ${typeof method} instead`); | ||
| 50 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', | ||
| 51 | + 'method', 'string', method); | ||
| 51 | 52 | } | |
| 52 | 53 | if (!callback && util.isFunction(params)) { | |
| 53 | 54 | callback = params; | |
| 54 | 55 | params = null; | |
| 55 | 56 | } | |
| 56 | 57 | if (params && typeof params !== 'object') { | |
| 57 | - throw new TypeError( | ||
| 58 | - `"params" must be an object, got ${typeof params} instead`); | ||
| 58 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', | ||
| 59 | + 'params', 'object', params); | ||
| 59 | 60 | } | |
| 60 | 61 | if (callback && typeof callback !== 'function') { | |
| 61 | - throw new TypeError( | ||
| 62 | - `"callback" must be a function, got ${typeof callback} instead`); | ||
| 62 | + throw new errors.TypeError('ERR_INVALID_CALLBACK'); | ||
| 63 | 63 | } | |
| 64 | 64 | ||
| 65 | 65 | if (!this[connectionSymbol]) { | |
| 66 | - throw new Error('Session is not connected'); | ||
| 66 | + throw new errors.Error('ERR_INSPECTOR_NOT_CONNECTED'); | ||
| 67 | 67 | } | |
| 68 | 68 | const id = this[nextIdSymbol]++; | |
| 69 | 69 | const message = { id, method }; | |
@@ -83,7 +83,7 @@ class Session extends EventEmitter { | |||
| 83 | 83 | this[connectionSymbol] = null; | |
| 84 | 84 | const remainingCallbacks = this[messageCallbacksSymbol].values(); | |
| 85 | 85 | for (const callback of remainingCallbacks) { | |
| 86 | - process.nextTick(callback, new Error('Session was closed')); | ||
| 86 | + process.nextTick(callback, new errors.Error('ERR_INSPECTOR_CLOSED')); | ||
| 87 | 87 | } | |
| 88 | 88 | this[messageCallbacksSymbol].clear(); | |
| 89 | 89 | this[nextIdSymbol] = 1; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -236,6 +236,10 @@ E('ERR_HTTP_INVALID_STATUS_CODE', | |||
| 236 | 236 | E('ERR_HTTP_TRAILER_INVALID', | |
| 237 | 237 | 'Trailers are invalid with this transfer encoding'); | |
| 238 | 238 | E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range'); | |
| 239 | + E('ERR_INSPECTOR_ALREADY_CONNECTED', 'The inspector is already connected'); | ||
| 240 | + E('ERR_INSPECTOR_CLOSED', 'Session was closed'); | ||
| 241 | + E('ERR_INSPECTOR_NOT_AVAILABLE', 'Inspector is not available'); | ||
| 242 | + E('ERR_INSPECTOR_NOT_CONNECTED', 'Session is not connected'); | ||
| 239 | 243 | E('ERR_INVALID_ARG_TYPE', invalidArgType); | |
| 240 | 244 | E('ERR_INVALID_ARG_VALUE', | |
| 241 | 245 | (name, value) => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,62 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + | ||
| 5 | + common.skipIfInspectorDisabled(); | ||
| 6 | + | ||
| 7 | + const assert = require('assert'); | ||
| 8 | + const { Session } = require('inspector'); | ||
| 9 | + | ||
| 10 | + const session = new Session(); | ||
| 11 | + | ||
| 12 | + common.expectsError( | ||
| 13 | + () => session.post('Runtime.evaluate', { expression: '2 + 2' }), | ||
| 14 | + { | ||
| 15 | + code: 'ERR_INSPECTOR_NOT_CONNECTED', | ||
| 16 | + type: Error, | ||
| 17 | + message: 'Session is not connected' | ||
| 18 | + } | ||
| 19 | + ); | ||
| 20 | + | ||
| 21 | + assert.doesNotThrow(() => session.connect()); | ||
| 22 | + | ||
| 23 | + assert.doesNotThrow( | ||
| 24 | + () => session.post('Runtime.evaluate', { expression: '2 + 2' })); | ||
| 25 | + | ||
| 26 | + [1, {}, [], true, Infinity, undefined].forEach((i) => { | ||
| 27 | + common.expectsError( | ||
| 28 | + () => session.post(i), | ||
| 29 | + { | ||
| 30 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 31 | + type: TypeError, | ||
| 32 | + message: | ||
| 33 | + 'The "method" argument must be of type string. ' + | ||
| 34 | + `Received type ${typeof i}` | ||
| 35 | + } | ||
| 36 | + ); | ||
| 37 | + }); | ||
| 38 | + | ||
| 39 | + [1, true, Infinity].forEach((i) => { | ||
| 40 | + common.expectsError( | ||
| 41 | + () => session.post('test', i), | ||
| 42 | + { | ||
| 43 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 44 | + type: TypeError, | ||
| 45 | + message: | ||
| 46 | + 'The "params" argument must be of type object. ' + | ||
| 47 | + `Received type ${typeof i}` | ||
| 48 | + } | ||
| 49 | + ); | ||
| 50 | + }); | ||
| 51 | + | ||
| 52 | + common.expectsError( | ||
| 53 | + () => session.connect(), | ||
| 54 | + { | ||
| 55 | + code: 'ERR_INSPECTOR_ALREADY_CONNECTED', | ||
| 56 | + type: Error, | ||
| 57 | + message: 'The inspector is already connected' | ||
| 58 | + } | ||
| 59 | + ); | ||
| 60 | + | ||
| 61 | + assert.doesNotThrow(() => session.disconnect()); | ||
| 62 | + assert.doesNotThrow(() => session.disconnect()); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments