Skip to content

Commit bb4078c

Browse files
committed
fix #392, #379
1 parent 04842a7 commit bb4078c

1 file changed

Lines changed: 36 additions & 27 deletions

File tree

src/client/debugger/Main.ts

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
"use strict";
22

3-
import {Variable, DebugSession, InitializedEvent, TerminatedEvent, StoppedEvent, OutputEvent, Thread, StackFrame, Scope, Source, Handles} from "vscode-debugadapter";
4-
import {ThreadEvent} from "vscode-debugadapter";
5-
import {DebugProtocol} from "vscode-debugprotocol";
6-
import {readFileSync} from "fs";
7-
import {basename} from "path";
3+
import { Variable, DebugSession, InitializedEvent, TerminatedEvent, StoppedEvent, OutputEvent, Thread, StackFrame, Scope, Source, Handles } from "vscode-debugadapter";
4+
import { ThreadEvent } from "vscode-debugadapter";
5+
import { DebugProtocol } from "vscode-debugprotocol";
6+
import { readFileSync } from "fs";
7+
import { basename } from "path";
88
import * as path from "path";
99
import * as os from "os";
1010
import * as fs from "fs";
1111
import * as child_process from "child_process";
1212
import * as StringDecoder from "string_decoder";
1313
import * as net from "net";
14-
import {PythonProcess} from "./PythonProcess";
15-
import {FrameKind, IPythonProcess, IPythonThread, IPythonModule, IPythonEvaluationResult, IPythonStackFrame, IDebugServer} from "./Common/Contracts";
16-
import {IPythonBreakpoint, PythonBreakpointConditionKind, PythonBreakpointPassCountKind, IPythonException, PythonEvaluationResultReprKind, enum_EXCEPTION_STATE} from "./Common/Contracts";
17-
import {BaseDebugServer} from "./DebugServers/BaseDebugServer";
18-
import {DebugClient, DebugType} from "./DebugClients/DebugClient";
19-
import {CreateAttachDebugClient, CreateLaunchDebugClient} from "./DebugClients/DebugFactory";
20-
import {DjangoApp, LaunchRequestArguments, AttachRequestArguments, DebugFlags, DebugOptions, TelemetryEvent, PythonEvaluationResultFlags} from "./Common/Contracts";
14+
import { PythonProcess } from "./PythonProcess";
15+
import { FrameKind, IPythonProcess, IPythonThread, IPythonModule, IPythonEvaluationResult, IPythonStackFrame, IDebugServer } from "./Common/Contracts";
16+
import { IPythonBreakpoint, PythonBreakpointConditionKind, PythonBreakpointPassCountKind, IPythonException, PythonEvaluationResultReprKind, enum_EXCEPTION_STATE } from "./Common/Contracts";
17+
import { BaseDebugServer } from "./DebugServers/BaseDebugServer";
18+
import { DebugClient, DebugType } from "./DebugClients/DebugClient";
19+
import { CreateAttachDebugClient, CreateLaunchDebugClient } from "./DebugClients/DebugFactory";
20+
import { DjangoApp, LaunchRequestArguments, AttachRequestArguments, DebugFlags, DebugOptions, TelemetryEvent, PythonEvaluationResultFlags } from "./Common/Contracts";
2121
import * as telemetryContracts from "../common/telemetryContracts";
22-
import {validatePath, validatePathSync} from './Common/Utils';
23-
import {isNotInstalledError} from '../common/helpers';
22+
import { validatePath, validatePathSync } from './Common/Utils';
23+
import { isNotInstalledError } from '../common/helpers';
2424

2525
const CHILD_ENUMEARATION_TIMEOUT = 5000;
2626

@@ -41,7 +41,7 @@ export class PythonDebugger extends DebugSession {
4141
private configurationDone: Promise<any>;
4242
private configurationDonePromiseResolve: () => void;
4343
private lastException: IPythonException;
44-
private _supportsRunInTerminalRequest:boolean;
44+
private _supportsRunInTerminalRequest: boolean;
4545
public constructor(debuggerLinesStartAt1: boolean, isServer: boolean) {
4646
super(debuggerLinesStartAt1, isServer === true);
4747
this._variableHandles = new Handles<IDebugVariable>();
@@ -70,8 +70,8 @@ export class PythonDebugger extends DebugSession {
7070
}
7171
];
7272
if (typeof args.supportsRunInTerminalRequest === 'boolean') {
73-
this._supportsRunInTerminalRequest = args.supportsRunInTerminalRequest;
74-
}
73+
this._supportsRunInTerminalRequest = args.supportsRunInTerminalRequest;
74+
}
7575
this.sendResponse(response);
7676
// now we are ready to accept breakpoints -> fire the initialized event to give UI a chance to set breakpoints
7777
this.sendEvent(new InitializedEvent());
@@ -147,7 +147,7 @@ export class PythonDebugger extends DebugSession {
147147
}
148148
// If launching the integrated terminal is not supported, then defer to external terminal
149149
// that will be displayed by our own code
150-
if (!this._supportsRunInTerminalRequest && this.launchArgs && this.launchArgs.console === 'integratedTerminal'){
150+
if (!this._supportsRunInTerminalRequest && this.launchArgs && this.launchArgs.console === 'integratedTerminal') {
151151
this.launchArgs.console = 'externalTerminal';
152152
}
153153
if (this.launchArgs && this.launchArgs.stopOnEntry === true) {
@@ -499,13 +499,13 @@ export class PythonDebugger extends DebugSession {
499499
TypeName: 'string', IsExpandable: false, HexRepr: '',
500500
ChildName: '', ExceptionText: '', Length: 0, Process: null
501501
},
502-
{
503-
Frame: frame, Expression: 'Description',
504-
Flags: PythonEvaluationResultFlags.Raw,
505-
StringRepr: this.lastException.Description,
506-
TypeName: 'string', IsExpandable: false, HexRepr: '',
507-
ChildName: '', ExceptionText: '', Length: 0, Process: null
508-
}],
502+
{
503+
Frame: frame, Expression: 'Description',
504+
Flags: PythonEvaluationResultFlags.Raw,
505+
StringRepr: this.lastException.Description,
506+
TypeName: 'string', IsExpandable: false, HexRepr: '',
507+
ChildName: '', ExceptionText: '', Length: 0, Process: null
508+
}],
509509
evaluateChildren: false
510510
};
511511
scopes.push(new Scope("Exception", this._variableHandles.create(values), false));
@@ -598,12 +598,11 @@ export class PythonDebugger extends DebugSession {
598598
if (args.filters.indexOf("all") >= 0) {
599599
mode = enum_EXCEPTION_STATE.BREAK_MODE_ALWAYS;
600600
}
601-
let exToIgnore = null;
601+
let exToIgnore = new Map<string, enum_EXCEPTION_STATE>();
602602
let exceptionHandling = this.launchArgs ? this.launchArgs.exceptionHandling : null;
603603
// Todo: exception handling for remote debugging
604604
// let exceptionHandling = this.launchArgs ? this.launchArgs.exceptionHandling : this.attachArgs.exceptionHandling;
605605
if (exceptionHandling) {
606-
exToIgnore = new Map<string, enum_EXCEPTION_STATE>();
607606
if (Array.isArray(exceptionHandling.ignore)) {
608607
exceptionHandling.ignore.forEach(exType => {
609608
exToIgnore.set(exType, enum_EXCEPTION_STATE.BREAK_MODE_NEVER);
@@ -619,6 +618,16 @@ export class PythonDebugger extends DebugSession {
619618
exToIgnore.set(exType, enum_EXCEPTION_STATE.BREAK_MODE_UNHANDLED);
620619
});
621620
}
621+
622+
}
623+
// For some reason on python 3.5 iterating through generators throws the StopIteration, GeneratorExit Exceptions
624+
// https://docs.python.org/2/library/exceptions.html#exceptions.StandardError
625+
// Lets ignore them
626+
if (!exToIgnore.has('StopIteration')) {
627+
exToIgnore.set('StopIteration', enum_EXCEPTION_STATE.BREAK_MODE_NEVER);
628+
}
629+
if (!exToIgnore.has('GeneratorExit')) {
630+
exToIgnore.set('GeneratorExit', enum_EXCEPTION_STATE.BREAK_MODE_NEVER);
622631
}
623632
this.pythonProcess.SendExceptionInfo(mode, exToIgnore);
624633
this.sendResponse(response);

0 commit comments

Comments
 (0)