@@ -105,17 +105,17 @@ class IotjsDebugSession extends DebugSession {
105
105
this . log ( 'attachRequest' ) ;
106
106
107
107
if ( ! args . address || args . address === '' ) {
108
- this . sendErrorResponse ( response , 0 , 'Must specify an address' ) ;
108
+ this . sendErrorResponse ( response , new Error ( 'Must specify an address' ) ) ;
109
109
return ;
110
110
}
111
111
112
112
if ( ! args . port || args . port <= 0 || args . port > 35535 ) {
113
- this . sendErrorResponse ( response , 0 , 'Must specify a valid port' ) ;
113
+ this . sendErrorResponse ( response , new Error ( 'Must specify a valid port' ) ) ;
114
114
return ;
115
115
}
116
116
117
117
if ( ! args . localRoot || args . localRoot === '' ) {
118
- this . sendErrorResponse ( response , 0 , 'Must specify a localRoot' ) ;
118
+ this . sendErrorResponse ( response , new Error ( 'Must specify a localRoot' ) ) ;
119
119
return ;
120
120
}
121
121
@@ -187,7 +187,7 @@ class IotjsDebugSession extends DebugSession {
187
187
} )
188
188
. catch ( error => {
189
189
this . log ( error ) ;
190
- this . sendErrorResponse ( response , 0 , error . message ) ;
190
+ this . sendErrorResponse ( response , error ) ;
191
191
} )
192
192
. then ( ( ) => {
193
193
this . sendEvent ( new InitializedEvent ( ) ) ;
@@ -197,7 +197,7 @@ class IotjsDebugSession extends DebugSession {
197
197
protected launchRequest ( response : DebugProtocol . LaunchResponse , args : DebugProtocol . LaunchRequestArguments ) : void {
198
198
this . log ( 'launchRequest' ) ;
199
199
200
- this . sendErrorResponse ( response , 0 , 'Launching is not supported. Use Attach.' ) ;
200
+ this . sendErrorResponse ( response , new Error ( 'Launching is not supported. Use Attach.' ) ) ;
201
201
}
202
202
203
203
protected disconnectRequest (
@@ -224,7 +224,7 @@ class IotjsDebugSession extends DebugSession {
224
224
. then ( ( ) => {
225
225
this . sendResponse ( response ) ;
226
226
} )
227
- . catch ( error => this . sendErrorResponse ( response , 0 , ( < Error > error ) . message ) ) ;
227
+ . catch ( error => this . sendErrorResponse ( response , < Error > error ) ) ;
228
228
}
229
229
230
230
protected nextRequest ( response : DebugProtocol . NextResponse , args : DebugProtocol . NextArguments ) : void {
@@ -234,7 +234,7 @@ class IotjsDebugSession extends DebugSession {
234
234
. then ( ( ) => {
235
235
this . sendResponse ( response ) ;
236
236
} )
237
- . catch ( error => this . sendErrorResponse ( response , 0 , ( < Error > error ) . message ) ) ;
237
+ . catch ( error => this . sendErrorResponse ( response , < Error > error ) ) ;
238
238
}
239
239
240
240
protected stepInRequest ( response : DebugProtocol . StepInResponse , args : DebugProtocol . StepInArguments ) : void {
@@ -244,7 +244,7 @@ class IotjsDebugSession extends DebugSession {
244
244
. then ( ( ) => {
245
245
this . sendResponse ( response ) ;
246
246
} )
247
- . catch ( error => this . sendErrorResponse ( response , 0 , ( < Error > error ) . message ) ) ;
247
+ . catch ( error => this . sendErrorResponse ( response , < Error > error ) ) ;
248
248
}
249
249
250
250
protected stepOutRequest ( response : DebugProtocol . StepOutResponse , args : DebugProtocol . StepOutArguments ) : void {
@@ -254,7 +254,7 @@ class IotjsDebugSession extends DebugSession {
254
254
. then ( ( ) => {
255
255
this . sendResponse ( response ) ;
256
256
} )
257
- . catch ( error => this . sendErrorResponse ( response , 0 , ( < Error > error ) . message ) ) ;
257
+ . catch ( error => this . sendErrorResponse ( response , < Error > error ) ) ;
258
258
}
259
259
260
260
protected pauseRequest ( response : DebugProtocol . PauseResponse , args : DebugProtocol . PauseArguments ) : void {
@@ -264,7 +264,7 @@ class IotjsDebugSession extends DebugSession {
264
264
. then ( ( ) => {
265
265
this . sendResponse ( response ) ;
266
266
} )
267
- . catch ( error => this . sendErrorResponse ( response , 0 , ( < Error > error ) . message ) ) ;
267
+ . catch ( error => this . sendErrorResponse ( response , < Error > error ) ) ;
268
268
}
269
269
270
270
protected async setBreakPointsRequest (
@@ -312,7 +312,7 @@ class IotjsDebugSession extends DebugSession {
312
312
response . body = { breakpoints : [ ...persistingBreakpoints , ...newBreakpoints ] } ;
313
313
} catch ( error ) {
314
314
this . log ( error ) ;
315
- this . sendErrorResponse ( response , 0 , ( < Error > error ) . message ) ;
315
+ this . sendErrorResponse ( response , < Error > error ) ;
316
316
return ;
317
317
}
318
318
@@ -333,7 +333,7 @@ class IotjsDebugSession extends DebugSession {
333
333
334
334
this . sendResponse ( response ) ;
335
335
} )
336
- . catch ( error => this . sendErrorResponse ( response , 0 , ( < Error > error ) . message ) ) ;
336
+ . catch ( error => this . sendErrorResponse ( response , < Error > error ) ) ;
337
337
}
338
338
339
339
protected stackTraceRequest (
@@ -359,7 +359,7 @@ class IotjsDebugSession extends DebugSession {
359
359
360
360
this . sendResponse ( response ) ;
361
361
} )
362
- . catch ( error => this . sendErrorResponse ( response , 0 , ( < Error > error ) . message ) ) ;
362
+ . catch ( error => this . sendErrorResponse ( response , < Error > error ) ) ;
363
363
}
364
364
365
365
protected customRequest ( command : string , response : DebugProtocol . Response , args : any ) : void {
@@ -377,7 +377,7 @@ class IotjsDebugSession extends DebugSession {
377
377
. catch ( error => {
378
378
this . log ( error ) ;
379
379
this . _sourceSendingOptions . state = SOURCE_SENDING_STATES . NOP ;
380
- this . sendErrorResponse ( response , 0 , ( < Error > error ) . message , null , ErrorDestination . User ) ;
380
+ this . sendErrorResponse ( response , < Error > error , ErrorDestination . User ) ;
381
381
} ) ;
382
382
return ;
383
383
}
@@ -386,6 +386,45 @@ class IotjsDebugSession extends DebugSession {
386
386
}
387
387
}
388
388
389
+ // Overrides.
390
+
391
+ protected sendErrorResponse (
392
+ response : DebugProtocol . Response ,
393
+ error : Error ,
394
+ dest ?: ErrorDestination
395
+ ) : void ;
396
+
397
+ protected sendErrorResponse (
398
+ response : DebugProtocol . Response ,
399
+ codeOrMessage : number | DebugProtocol . Message ,
400
+ format ?: string ,
401
+ variables ?: any ,
402
+ dest ?: ErrorDestination
403
+ ) : void ;
404
+
405
+ protected sendErrorResponse ( response : DebugProtocol . Response ) {
406
+ if ( arguments [ 1 ] instanceof Error ) {
407
+ const error = arguments [ 1 ] as Error & { code ?: number | string ; errno ?: number } ;
408
+ const dest = arguments [ 2 ] as ErrorDestination ;
409
+
410
+ let code : number ;
411
+
412
+ if ( typeof error . code === 'number' ) {
413
+ code = error . code as number ;
414
+ } else if ( typeof error . errno === 'number' ) {
415
+ code = error . errno ;
416
+ } else {
417
+ code = 0 ;
418
+ }
419
+
420
+ super . sendErrorResponse ( response , code , error . message , dest ) ;
421
+ } else {
422
+ super . sendErrorResponse ( response , arguments [ 1 ] , arguments [ 2 ] , arguments [ 3 ] , arguments [ 4 ] ) ;
423
+ }
424
+ }
425
+
426
+ // Helper functions
427
+
389
428
private handleSource ( data : JerryMessageScriptParsed ) : void {
390
429
const path = `${ this . _args . localRoot } /${ this . pathToBasename ( data . name ) } ` ;
391
430
const src = this . _protocolhandler . getSource ( data . id ) ;
0 commit comments