Skip to content

Commit ba9c6be

Browse files
committed
display exception info in variables section #271
1 parent 69d133b commit ba9c6be

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/client/debugger/Main.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {IPythonBreakpoint, PythonBreakpointConditionKind, PythonBreakpointPassCo
1717
import {BaseDebugServer} from "./DebugServers/BaseDebugServer";
1818
import {DebugClient, DebugType} from "./DebugClients/DebugClient";
1919
import {CreateAttachDebugClient, CreateLaunchDebugClient} from "./DebugClients/DebugFactory";
20-
import {DjangoApp, LaunchRequestArguments, AttachRequestArguments, DebugFlags, DebugOptions, TelemetryEvent} from "./Common/Contracts";
20+
import {DjangoApp, LaunchRequestArguments, AttachRequestArguments, DebugFlags, DebugOptions, TelemetryEvent, PythonEvaluationResultFlags} from "./Common/Contracts";
2121
import * as telemetryContracts from "../common/telemetryContracts";
2222
import {validatePath} from './Common/Utils';
2323

@@ -39,7 +39,7 @@ export class PythonDebugger extends DebugSession {
3939
private debugClient: DebugClient;
4040
private configurationDone: Promise<any>;
4141
private configurationDonePromiseResolve: () => void;
42-
42+
private lastException: IPythonException;
4343
public constructor(debuggerLinesStartAt1: boolean, isServer: boolean) {
4444
super(debuggerLinesStartAt1, isServer === true);
4545
this._variableHandles = new Handles<IDebugVariable>();
@@ -120,6 +120,7 @@ export class PythonDebugger extends DebugSession {
120120
this.sendEvent(new StoppedEvent("step", pyThread.Id));
121121
}
122122
private onPythonException(pyThread: IPythonThread, ex: IPythonException) {
123+
this.lastException = ex;
123124
this.sendEvent(new StoppedEvent("exception", pyThread.Id, `${ex.TypeName}, ${ex.Description}`));
124125
this.sendEvent(new OutputEvent(`${ex.TypeName}, ${ex.Description}\n`, "stderr"));
125126
}
@@ -462,6 +463,27 @@ export class PythonDebugger extends DebugSession {
462463
}
463464

464465
let scopes = [];
466+
if (typeof this.lastException === 'object' && this.lastException !== null && this.lastException.Description.length > 0) {
467+
let values: IDebugVariable = {
468+
variables: [{
469+
Frame: frame, Expression: 'Type',
470+
Flags: PythonEvaluationResultFlags.Raw,
471+
StringRepr: this.lastException.TypeName,
472+
TypeName: 'string', IsExpandable: false, HexRepr: '',
473+
ChildName: '', ExceptionText: '', Length: 0, Process: null
474+
},
475+
{
476+
Frame: frame, Expression: 'Description',
477+
Flags: PythonEvaluationResultFlags.Raw,
478+
StringRepr: this.lastException.Description,
479+
TypeName: 'string', IsExpandable: false, HexRepr: '',
480+
ChildName: '', ExceptionText: '', Length: 0, Process: null
481+
}],
482+
evaluateChildren: false
483+
};
484+
scopes.push(new Scope("Exception", this._variableHandles.create(values), false));
485+
this.lastException = null;
486+
}
465487
if (Array.isArray(frame.Locals) && frame.Locals.length > 0) {
466488
let values: IDebugVariable = { variables: frame.Locals };
467489
scopes.push(new Scope("Local", this._variableHandles.create(values), false));

0 commit comments

Comments
 (0)