Skip to content

Commit f8dee7a

Browse files
knightburtonyichoi
authored andcommitted
Change the error messages to error object. (#34)
IoT.js-Debug-DCO-1.0-Signed-off-by: Imre Kiss [email protected]
1 parent 0318e12 commit f8dee7a

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/IotjsDebugger.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class IotjsDebugSession extends DebugSession {
224224
.then(() => {
225225
this.sendResponse(response);
226226
})
227-
.catch(error => this.sendErrorResponse(response, 0, error));
227+
.catch(error => this.sendErrorResponse(response, 0, (<Error>error).message));
228228
}
229229

230230
protected nextRequest(response: DebugProtocol.NextResponse, args: DebugProtocol.NextArguments): void {
@@ -234,7 +234,7 @@ class IotjsDebugSession extends DebugSession {
234234
.then(() => {
235235
this.sendResponse(response);
236236
})
237-
.catch(error => this.sendErrorResponse(response, 0, error));
237+
.catch(error => this.sendErrorResponse(response, 0, (<Error>error).message));
238238
}
239239

240240
protected stepInRequest(response: DebugProtocol.StepInResponse, args: DebugProtocol.StepInArguments): void {
@@ -244,7 +244,7 @@ class IotjsDebugSession extends DebugSession {
244244
.then(() => {
245245
this.sendResponse(response);
246246
})
247-
.catch(error => this.sendErrorResponse(response, 0, error));
247+
.catch(error => this.sendErrorResponse(response, 0, (<Error>error).message));
248248
}
249249

250250
protected stepOutRequest(response: DebugProtocol.StepOutResponse, args: DebugProtocol.StepOutArguments): void {
@@ -254,7 +254,7 @@ class IotjsDebugSession extends DebugSession {
254254
.then(() => {
255255
this.sendResponse(response);
256256
})
257-
.catch(error => this.sendErrorResponse(response, 0, error));
257+
.catch(error => this.sendErrorResponse(response, 0, (<Error>error).message));
258258
}
259259

260260
protected pauseRequest(response: DebugProtocol.PauseResponse, args: DebugProtocol.PauseArguments): void {
@@ -264,7 +264,7 @@ class IotjsDebugSession extends DebugSession {
264264
.then(() => {
265265
this.sendResponse(response);
266266
})
267-
.catch(error => this.sendErrorResponse(response, 0, error));
267+
.catch(error => this.sendErrorResponse(response, 0, (<Error>error).message));
268268
}
269269

270270
protected async setBreakPointsRequest(
@@ -311,8 +311,8 @@ class IotjsDebugSession extends DebugSession {
311311

312312
response.body = { breakpoints: [...persistingBreakpoints, ...newBreakpoints] };
313313
} catch (error) {
314-
this.log(error.message);
315-
this.sendErrorResponse(response, error.message);
314+
this.log(error);
315+
this.sendErrorResponse(response, 0, (<Error>error).message);
316316
return;
317317
}
318318

@@ -333,7 +333,7 @@ class IotjsDebugSession extends DebugSession {
333333

334334
this.sendResponse(response);
335335
})
336-
.catch(error => this.sendErrorResponse(response, 0, error));
336+
.catch(error => this.sendErrorResponse(response, 0, (<Error>error).message));
337337
}
338338

339339
protected stackTraceRequest(
@@ -359,7 +359,7 @@ class IotjsDebugSession extends DebugSession {
359359

360360
this.sendResponse(response);
361361
})
362-
.catch(error => this.sendErrorResponse(response, 0, error));
362+
.catch(error => this.sendErrorResponse(response, 0, (<Error>error).message));
363363
}
364364

365365
protected customRequest(command: string, response: DebugProtocol.Response, args: any): void {
@@ -377,7 +377,7 @@ class IotjsDebugSession extends DebugSession {
377377
.catch(error => {
378378
this.log(error);
379379
this._sourceSendingOptions.state = SOURCE_SENDING_STATES.NOP;
380-
this.sendErrorResponse(response, 0, error, null, ErrorDestination.User);
380+
this.sendErrorResponse(response, 0, (<Error>error).message, null, ErrorDestination.User);
381381
});
382382
return;
383383
}

src/JerryProtocolHandler.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export class JerryDebugProtocolHandler {
211211

212212
public pause(): Promise<any> {
213213
if (this.lastBreakpointHit) {
214-
return Promise.reject('attempted pause while at breakpoint');
214+
return Promise.reject(new Error('attempted pause while at breakpoint'));
215215
}
216216
return this.sendSimpleRequest(encodeMessage(this.byteConfig, 'B', [SP.CLIENT.JERRY_DEBUGGER_STOP]));
217217
}
@@ -626,7 +626,7 @@ export class JerryDebugProtocolHandler {
626626

627627
public evaluate(expression: string): Promise<any> {
628628
if (!this.lastBreakpointHit) {
629-
return Promise.reject('attempted eval while not at breakpoint');
629+
return Promise.reject(new Error('attempted eval while not at breakpoint'));
630630
}
631631

632632
this.evalsPending++;
@@ -697,7 +697,7 @@ export class JerryDebugProtocolHandler {
697697

698698
public requestBacktrace(): Promise<any> {
699699
if (!this.lastBreakpointHit) {
700-
return Promise.reject('backtrace not allowed while app running');
700+
return Promise.reject(new Error('backtrace not allowed while app running'));
701701
}
702702
return this.sendRequest(encodeMessage(this.byteConfig, 'BI', [SP.CLIENT.JERRY_DEBUGGER_GET_BACKTRACE, 0]));
703703
}
@@ -717,7 +717,7 @@ export class JerryDebugProtocolHandler {
717717

718718
private resumeExec(code: number): Promise<any> {
719719
if (!this.lastBreakpointHit) {
720-
return Promise.reject('attempted resume while not at breakpoint');
720+
return Promise.reject(new Error('attempted resume while not at breakpoint'));
721721
}
722722

723723
this.lastBreakpointHit = undefined;
@@ -732,7 +732,7 @@ export class JerryDebugProtocolHandler {
732732

733733
public sendClientSource(fileName: string, fileSourceCode: string): Promise<any> {
734734
if (!this.waitForSourceEnabled) {
735-
return Promise.reject('wait-for-source not enabled');
735+
return Promise.reject(new Error('wait-for-source not enabled'));
736736
}
737737

738738
this.waitForSourceEnabled = false;
@@ -762,7 +762,7 @@ export class JerryDebugProtocolHandler {
762762
const validCodes: number[] = [SP.CLIENT.JERRY_DEBUGGER_NO_MORE_SOURCES, SP.CLIENT.JERRY_DEBUGGER_CONTEXT_RESET];
763763

764764
if (validCodes.indexOf(code) === -1) {
765-
return Promise.reject('Invalid source sending control code.');
765+
return Promise.reject(new Error('Invalid source sending control code.'));
766766
}
767767

768768
return this.sendSimpleRequest(encodeMessage(this.byteConfig, 'B', [code]));
@@ -782,7 +782,7 @@ export class JerryDebugProtocolHandler {
782782
this.requestQueue = [...this.requestQueue, request];
783783
} else {
784784
if (!this.submitRequest(request)) {
785-
return Promise.reject('Failed to submit request.');
785+
return Promise.reject(new Error('Failed to submit request.'));
786786
}
787787
}
788788

@@ -793,7 +793,7 @@ export class JerryDebugProtocolHandler {
793793
const request = new PendingRequest(data);
794794

795795
if (!this.submitRequest(request, true)) {
796-
return Promise.reject('Failed to submit request.');
796+
return Promise.reject(new Error('Failed to submit request.'));
797797
}
798798

799799
return Promise.resolve();

src/test/JerryProtocolHandler.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ suite('JerryProtocolHandler', () => {
545545
const handler = new JerryDebugProtocolHandler({});
546546
await handler.requestBacktrace()
547547
.catch(error => {
548-
assert.strictEqual(error, 'backtrace not allowed while app running');
548+
assert.strictEqual((<Error>error).message, 'backtrace not allowed while app running');
549549
});
550550
});
551551

0 commit comments

Comments
 (0)