Skip to content

Commit a740016

Browse files
authored
Ensure debugger breaks on assert failures (microsoft#1599)
Fixes microsoft#1194
1 parent 3e11c29 commit a740016

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

news/2 Fixes/1194.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure debugger breaks on `assert` failures.

src/client/debugger/PythonProcessCallbackHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class PythonProcessCallbackHandler extends EventEmitter {
259259
return;
260260
}
261261

262-
if (typeName && desc) {
262+
if (typeName || desc) {
263263
let ex: IPythonException = {
264264
TypeName: typeName,
265265
Description: desc

src/test/debugger/misc.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,42 @@ let testCounter = 0;
440440
const pauseLocation = { path: path.join(debugFilesPath, 'sample3WithEx.py'), line: 5 };
441441
await debugClient.assertStoppedLocation('exception', pauseLocation);
442442
});
443+
test('Test pausing on assert failures', async () => {
444+
const pauseLocation = { path: path.join(debugFilesPath, 'sampleWithAssertEx.py'), line: 1 };
445+
446+
function waitToStopDueToException() {
447+
return new Promise((resolve, reject) => {
448+
debugClient.once('stopped', (event: DebugProtocol.StoppedEvent) => {
449+
if (event.body.reason === 'exception' &&
450+
event.body.text && event.body.text!.startsWith('AssertionError')) {
451+
resolve();
452+
} else {
453+
reject(new Error('Stopped for some other reason'));
454+
}
455+
});
456+
setTimeout(() => {
457+
reject(new Error(`waitToStopDueToException not received after ${debugClient.defaultTimeout} ms`));
458+
}, debugClient.defaultTimeout);
459+
});
460+
}
461+
462+
function setBreakpointFilter(): Promise<any> {
463+
if (debuggerType === 'python') {
464+
return Promise.resolve();
465+
} else {
466+
return debugClient.waitForEvent('initialized')
467+
.then(() => debugClient.setExceptionBreakpointsRequest({ filters: ['uncaught'] }))
468+
.then(() => debugClient.configurationDoneRequest());
469+
}
470+
}
471+
await Promise.all([
472+
debugClient.configurationSequence(),
473+
setBreakpointFilter(),
474+
debugClient.launch(buildLauncArgs('sampleWithAssertEx.py', false)),
475+
waitToStopDueToException(),
476+
debugClient.assertStoppedLocation('exception', pauseLocation)
477+
]);
478+
});
443479
test('Test multi-threaded debugging', async function () {
444480
if (debuggerType !== 'python') {
445481
// See GitHub issue #1250
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assert False

0 commit comments

Comments
 (0)