Improved error responses

This commit is contained in:
WebFreak001 2016-03-06 12:08:57 +01:00
commit e671d4cba0
2 changed files with 27 additions and 38 deletions

View file

@ -239,7 +239,7 @@ export class MI2 extends EventEmitter implements IBackend {
} }
} }
if (parsed.resultRecords && parsed.resultRecords.resultClass == "error") { if (parsed.resultRecords && parsed.resultRecords.resultClass == "error") {
this.log("log", "An error occured: " + parsed.result("msg")); this.log("stderr", parsed.result("msg") || line);
} }
if (parsed.outOfBandRecord) { if (parsed.outOfBandRecord) {
parsed.outOfBandRecord.forEach(record => { parsed.outOfBandRecord.forEach(record => {

View file

@ -26,7 +26,7 @@ export class MI2DebugSession extends DebugSession {
public constructor(debuggerLinesStartAt1: boolean, isServer: boolean = false) { public constructor(debuggerLinesStartAt1: boolean, isServer: boolean = false) {
super(debuggerLinesStartAt1, isServer); super(debuggerLinesStartAt1, isServer);
} }
protected initDebugger() { protected initDebugger() {
this.miDebugger.on("quit", this.quitEvent.bind(this)); this.miDebugger.on("quit", this.quitEvent.bind(this));
this.miDebugger.on("exited-normally", this.quitEvent.bind(this)); this.miDebugger.on("exited-normally", this.quitEvent.bind(this));
@ -142,8 +142,7 @@ export class MI2DebugSession extends DebugSession {
this.miDebugger.continue().then(done => { this.miDebugger.continue().then(done => {
this.sendResponse(response); this.sendResponse(response);
}, msg => { }, msg => {
this.sendResponse(response); this.sendErrorResponse(response, 2, `Could not continue: ${msg}`);
this.sendEvent(new OutputEvent(`Could not continue: ${msg}\n`, 'stderr'));
}); });
} }
else else
@ -197,37 +196,32 @@ export class MI2DebugSession extends DebugSession {
}; };
this.sendResponse(response); this.sendResponse(response);
}, err => { }, err => {
this.handleMsg("stderr", "Could not expand variable\n"); this.sendErrorResponse(response, 1, `Could not expand variable: ${err}`);
response.body = {
variables: []
};
this.sendResponse(response);
}); });
} }
else { else {
// Variable members // Variable members
this.miDebugger.evalExpression(JSON.stringify(id)).then(variable => { this.miDebugger.evalExpression(JSON.stringify(id)).then(variable => {
let expanded = expandValue(createVariable, variable.result("value"), id); let expanded = expandValue(createVariable, variable.result("value"), id);
if (!expanded) if (!expanded) {
this.sendEvent(new OutputEvent("Could not expand " + variable.result("value") + "\n", "stderr")); this.sendErrorResponse(response, 2, `Could not expand variable`);
else if (typeof expanded[0] == "string") }
expanded = [ else {
{ if (typeof expanded[0] == "string")
name: "<value>", expanded = [
value: prettyStringArray(expanded), {
variablesReference: 0 name: "<value>",
} value: prettyStringArray(expanded),
]; variablesReference: 0
response.body = { }
variables: expanded ];
}; response.body = {
this.sendResponse(response); variables: expanded
};
this.sendResponse(response);
}
}, err => { }, err => {
this.handleMsg("stderr", "Could not expand variable\n"); this.sendErrorResponse(response, 1, `Could not expand variable`);
response.body = {
variables: []
};
this.sendResponse(response);
}); });
} }
} }
@ -249,8 +243,7 @@ export class MI2DebugSession extends DebugSession {
this.miDebugger.interrupt().then(done => { this.miDebugger.interrupt().then(done => {
this.sendResponse(response); this.sendResponse(response);
}, msg => { }, msg => {
this.sendResponse(response); this.sendErrorResponse(response, 3, `Could not pause: ${msg}`);
this.sendEvent(new OutputEvent(`Could not pause: ${msg}\n`, 'stderr'));
}); });
} }
@ -258,8 +251,7 @@ export class MI2DebugSession extends DebugSession {
this.miDebugger.continue().then(done => { this.miDebugger.continue().then(done => {
this.sendResponse(response); this.sendResponse(response);
}, msg => { }, msg => {
this.sendResponse(response); this.sendErrorResponse(response, 2, `Could not continue: ${msg}`);
this.sendEvent(new OutputEvent(`Could not continue: ${msg}\n`, 'stderr'));
}); });
} }
@ -267,8 +259,7 @@ export class MI2DebugSession extends DebugSession {
this.miDebugger.step().then(done => { this.miDebugger.step().then(done => {
this.sendResponse(response); this.sendResponse(response);
}, msg => { }, msg => {
this.sendResponse(response); this.sendErrorResponse(response, 4, `Could not step in: ${msg}`);
this.sendEvent(new OutputEvent(`Could not step in: ${msg}\n`, 'stderr'));
}); });
} }
@ -276,8 +267,7 @@ export class MI2DebugSession extends DebugSession {
this.miDebugger.stepOut().then(done => { this.miDebugger.stepOut().then(done => {
this.sendResponse(response); this.sendResponse(response);
}, msg => { }, msg => {
this.sendResponse(response); this.sendErrorResponse(response, 5, `Could not step out: ${msg}`);
this.sendEvent(new OutputEvent(`Could not step out: ${msg}\n`, 'stderr'));
}); });
} }
@ -285,8 +275,7 @@ export class MI2DebugSession extends DebugSession {
this.miDebugger.next().then(done => { this.miDebugger.next().then(done => {
this.sendResponse(response); this.sendResponse(response);
}, msg => { }, msg => {
this.sendResponse(response); this.sendErrorResponse(response, 6, `Could not step over: ${msg}`);
this.sendEvent(new OutputEvent(`Could not step over: ${msg}\n`, 'stderr'));
}); });
} }