Skip to content

Commit

Permalink
debug: handle incorrect json objects from adapter better
Browse files Browse the repository at this point in the history
fixes #2470
  • Loading branch information
isidorn committed Feb 5, 2016
1 parent 3a1619b commit 578d067
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/vs/workbench/parts/debug/node/rawDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ export class RawDebugSession extends v8.V8Protocol implements debug.IRawDebugSes
});
}

private onServerError(err: Error): void {
protected onServerError(err: Error): void {
this.messageService.show(severity.Error, nls.localize('stoppingDebugAdapter', "{0}. Stopping the debug adapter.", err.message));
this.stopServer().done(null, errors.onUnexpectedError);
this.messageService.show(severity.Error, err.message);
}

private onServerExit(): void {
Expand Down
31 changes: 18 additions & 13 deletions src/vs/workbench/parts/debug/node/v8Protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ee = require('vs/base/common/eventEmitter');
import { Promise, TPromise } from 'vs/base/common/winjs.base';
import debug = require('vs/workbench/parts/debug/common/debug');

export class V8Protocol extends ee.EventEmitter {
export abstract class V8Protocol extends ee.EventEmitter {

public emittedStopped: boolean;
public readyForBreakpoints: boolean;
Expand Down Expand Up @@ -46,7 +46,7 @@ export class V8Protocol extends ee.EventEmitter {
eventType === debug.SessionEvents.DEBUGEE_TERMINATED || eventType === debug.SessionEvents.SERVER_EXIT) {
this.flowEventsCount++;
}

if (data) {
data.sessionId = this.getId();
} else {
Expand Down Expand Up @@ -131,19 +131,24 @@ export class V8Protocol extends ee.EventEmitter {
}
}

private dispatch(body: string): void {
const rawData = JSON.parse(body);
protected abstract onServerError(err: Error): void;

if (typeof rawData.event !== 'undefined') {
const event = <DebugProtocol.Event> rawData;
this.emit(event.event, event);
} else {
const response = <DebugProtocol.Response> rawData;
const clb = this.pendingRequests[response.request_seq];
if (clb) {
delete this.pendingRequests[response.request_seq];
clb(response);
private dispatch(body: string): void {
try {
const rawData = JSON.parse(body);
if (typeof rawData.event !== 'undefined') {
const event = <DebugProtocol.Event> rawData;
this.emit(event.event, event);
} else {
const response = <DebugProtocol.Response> rawData;
const clb = this.pendingRequests[response.request_seq];
if (clb) {
delete this.pendingRequests[response.request_seq];
clb(response);
}
}
} catch (e) {
this.onServerError(new Error(e.message || e));
}
}
}

0 comments on commit 578d067

Please sign in to comment.