Don't swallow errors on varUpdate()
Add MIError class for exceptions. Check error type on varUpdate() failure and rethrow if it's not "Variable object not found".
This commit is contained in:
parent
aa1ea10c73
commit
ca0f86a37c
3 changed files with 48 additions and 8 deletions
|
|
@ -123,3 +123,38 @@ export class VariableObject {
|
|||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
// from https://gist.github.com/justmoon/15511f92e5216fa2624b#gistcomment-1928632
|
||||
export interface MIError extends Error {
|
||||
readonly name: string;
|
||||
readonly message: string;
|
||||
readonly source: string;
|
||||
};
|
||||
export interface MIErrorConstructor {
|
||||
new (message: string, source: string): MIError;
|
||||
readonly prototype: MIError;
|
||||
}
|
||||
|
||||
export const MIError: MIErrorConstructor = <any>class MIError {
|
||||
readonly name: string;
|
||||
readonly message: string;
|
||||
readonly source: string;
|
||||
public constructor(message: string, source: string) {
|
||||
Object.defineProperty(this, 'name', {
|
||||
get: () => (this.constructor as any).name,
|
||||
});
|
||||
Object.defineProperty(this, 'message', {
|
||||
get: () => message,
|
||||
});
|
||||
Object.defineProperty(this, 'source', {
|
||||
get: () => source,
|
||||
});
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
|
||||
public toString() {
|
||||
return `${this.message} (from ${this.source})`;
|
||||
}
|
||||
};
|
||||
Object.setPrototypeOf(MIError as any, Object.create(Error.prototype));
|
||||
MIError.prototype.constructor = MIError;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Breakpoint, IBackend, Stack, SSHArguments, Variable, VariableObject } from "../backend"
|
||||
import { Breakpoint, IBackend, Stack, SSHArguments, Variable, VariableObject, MIError } from "../backend"
|
||||
import * as ChildProcess from "child_process"
|
||||
import { EventEmitter } from "events"
|
||||
import { parseMI, MINode } from '../mi_parse';
|
||||
|
|
@ -729,11 +729,11 @@ export class MI2 extends EventEmitter implements IBackend {
|
|||
this.handlers[sel] = (node: MINode) => {
|
||||
if (node && node.resultRecords && node.resultRecords.resultClass === "error") {
|
||||
if (suppressFailure) {
|
||||
this.log("stderr", "WARNING: Error executing command '" + command + "'");
|
||||
this.log("stderr", `WARNING: Error executing command '${command}'`);
|
||||
resolve(node);
|
||||
}
|
||||
else
|
||||
reject((node.result("msg") || "Internal error") + " (from " + command + ")");
|
||||
reject(new MIError(node.result("msg") || "Internal error", command));
|
||||
}
|
||||
else
|
||||
resolve(node);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue