Skip to content

Commit

Permalink
Improve display of errors when evaluating variables + test failure me…
Browse files Browse the repository at this point in the history
…ssages
  • Loading branch information
DanTup committed Oct 29, 2019
1 parent 8624f4e commit a68e492
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
50 changes: 33 additions & 17 deletions src/debug/dart_debug_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,30 +815,38 @@ export class DartDebugSession extends DebugSession {
} else if (data.data.type === "MapEntry") {
const mapRef = data.data as VMMapEntry;

const results = await Promise.all([
this.observatory.getObject(thread.ref.id, mapRef.keyId),
this.observatory.getObject(thread.ref.id, mapRef.valueId),
]);
const keyResult = this.observatory.getObject(thread.ref.id, mapRef.keyId);
const valueResult = this.observatory.getObject(thread.ref.id, mapRef.valueId);

const variables: DebugProtocol.Variable[] = [];
let canEvaluateValueName = false;
let valueEvaluateName = "value";

const [keyDebuggerResult, valueDebuggerResult] = results;
const keyInstanceRef = keyDebuggerResult.result as VMInstanceRef;
const valueInstanceRef = valueDebuggerResult.result as VMInstanceRef;
try {
const keyDebuggerResult = await keyResult;
const keyInstanceRef = keyDebuggerResult.result as VMInstanceRef;

variables.push(await this.instanceRefToVariable(thread, false, "key", "key", keyInstanceRef, true));
variables.push(await this.instanceRefToVariable(thread, false, "key", "key", keyInstanceRef, true));

let canEvaluateValueName = false;
let valueEvaluateName = "value";
if (this.isSimpleKind(keyInstanceRef.kind)) {
canEvaluateValueName = true;
valueEvaluateName = `${mapRef.mapEvaluateName}[${this.valueAsString(keyInstanceRef)}]`;
if (this.isSimpleKind(keyInstanceRef.kind)) {
canEvaluateValueName = true;
valueEvaluateName = `${mapRef.mapEvaluateName}[${this.valueAsString(keyInstanceRef)}]`;
}
} catch (error) {
variables.push({ name: "key", value: this.errorAsDisplayValue(error), variablesReference: 0 });
}

variables.push(await this.instanceRefToVariable(thread, canEvaluateValueName, valueEvaluateName, "value", valueInstanceRef, true));
try {
const valueDebuggerResult = await valueResult;
const valueInstanceRef = valueDebuggerResult.result as VMInstanceRef;
variables.push(await this.instanceRefToVariable(thread, canEvaluateValueName, valueEvaluateName, "value", valueInstanceRef, true));
} catch (error) {
variables.push({ name: "value", value: this.errorAsDisplayValue(error), variablesReference: 0 });
}

response.body = { variables };
this.sendResponse(response);

} else {
const instanceRef = data.data as InstanceWithEvaluateName;

Expand Down Expand Up @@ -930,7 +938,7 @@ export class DartDebugSession extends DebugSession {
);
}
} catch (e) {
return { name: getterName, value: `<${e}>`, variablesReference: 0 };
return { name: getterName, value: this.errorAsDisplayValue(e), variablesReference: 0 };
}
});
fieldAndGetterPromises = fieldAndGetterPromises.concat(getterPromises);
Expand All @@ -951,17 +959,25 @@ export class DartDebugSession extends DebugSession {
response.body = { variables };
this.sendResponse(response);
} catch (error) {
// this.errorResponse(response, `${error}`);
response.body = {
variables: [
{ name: "<error>", value: `${error.message || error}`, variablesReference: 0 },
{ name: "<error>", value: this.errorAsDisplayValue(error), variablesReference: 0 },
],
};
this.sendResponse(response);
}
}
}

private errorAsDisplayValue(error: any) {
if (!error)
return `<unknown error>`;
const message = `${error.message || error}`;
if (!message)
return `<unknown error>`;
return `<${message.split("\n")[0].trim()}>`;
}

private async getGetterNamesForHierarchy(thread: VMIsolateRef, classRef: VMClassRef | undefined): Promise<string[]> {
let getterNames: string[] = [];
while (this.observatory && classRef) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/debug_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export async function ensureMapEntry(mapEntries: DebugProtocol.Variable[], entry

const key = variable[0] as DebugProtocol.Variable;
const value = variable[1] as DebugProtocol.Variable;
assert.ok(key);
assert.ok(value);
assert.ok(key, "Didn't get Key variable");
assert.ok(value, "Didn't get Value variable");
if (key.name === entry.key.name
&& key.value === entry.key.value
&& key.evaluateName === entry.key.evaluateName
Expand Down

0 comments on commit a68e492

Please sign in to comment.