11'use strict' ;
22
33const EventEmitter = require ( 'events' ) ;
4+ const errors = require ( 'internal/errors' ) ;
45const util = require ( 'util' ) ;
56const { Connection, open, url } = process . binding ( 'inspector' ) ;
67
78if ( ! Connection )
8- throw new Error ( 'Inspector is not available ' ) ;
9+ throw new errors . Error ( 'ERR_INSPECTOR_NOT_AVAILABLE ' ) ;
910
1011const connectionSymbol = Symbol ( 'connectionProperty' ) ;
1112const messageCallbacksSymbol = Symbol ( 'messageCallbacks' ) ;
@@ -22,7 +23,7 @@ class Session extends EventEmitter {
2223
2324 connect ( ) {
2425 if ( this [ connectionSymbol ] )
25- throw new Error ( 'Already connected ' ) ;
26+ throw new errors . Error ( 'ERR_INSPECTOR_ALREADY_CONNECTED ' ) ;
2627 this [ connectionSymbol ] =
2728 new Connection ( ( message ) => this [ onMessageSymbol ] ( message ) ) ;
2829 }
@@ -46,24 +47,23 @@ class Session extends EventEmitter {
4647
4748 post ( method , params , callback ) {
4849 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 ) ;
5152 }
5253 if ( ! callback && util . isFunction ( params ) ) {
5354 callback = params ;
5455 params = null ;
5556 }
5657 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 ) ;
5960 }
6061 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' ) ;
6363 }
6464
6565 if ( ! this [ connectionSymbol ] ) {
66- throw new Error ( 'Session is not connected ' ) ;
66+ throw new errors . Error ( 'ERR_INSPECTOR_NOT_CONNECTED ' ) ;
6767 }
6868 const id = this [ nextIdSymbol ] ++ ;
6969 const message = { id, method } ;
@@ -83,7 +83,7 @@ class Session extends EventEmitter {
8383 this [ connectionSymbol ] = null ;
8484 const remainingCallbacks = this [ messageCallbacksSymbol ] . values ( ) ;
8585 for ( const callback of remainingCallbacks ) {
86- process . nextTick ( callback , new Error ( 'Session was closed ' ) ) ;
86+ process . nextTick ( callback , new errors . Error ( 'ERR_INSPECTOR_CLOSED ' ) ) ;
8787 }
8888 this [ messageCallbacksSymbol ] . clear ( ) ;
8989 this [ nextIdSymbol ] = 1 ;
0 commit comments