Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2 Fixes/1194.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure debugger breaks on `assert` failures.
2 changes: 1 addition & 1 deletion src/client/debugger/PythonProcessCallbackHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export class PythonProcessCallbackHandler extends EventEmitter {
return;
}

if (typeName && desc) {
if (typeName || desc) {
let ex: IPythonException = {
TypeName: typeName,
Description: desc

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK to be undefined or does it need to be empty string for instance?

Expand Down
36 changes: 36 additions & 0 deletions src/test/debugger/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,42 @@ let testCounter = 0;
const pauseLocation = { path: path.join(debugFilesPath, 'sample3WithEx.py'), line: 5 };
await debugClient.assertStoppedLocation('exception', pauseLocation);
});
test('Test pausing on assert failures', async () => {
const pauseLocation = { path: path.join(debugFilesPath, 'sampleWithAssertEx.py'), line: 1 };

function waitToStopDueToException() {
return new Promise((resolve, reject) => {
debugClient.once('stopped', (event: DebugProtocol.StoppedEvent) => {
if (event.body.reason === 'exception' &&
event.body.text && event.body.text!.startsWith('AssertionError')) {
resolve();
} else {
reject(new Error('Stopped for some other reason'));
}
});
setTimeout(() => {
reject(new Error(`waitToStopDueToException not received after ${debugClient.defaultTimeout} ms`));
}, debugClient.defaultTimeout);
});
}

function setBreakpointFilter(): Promise<any> {
if (debuggerType === 'python') {
return Promise.resolve();
} else {
return debugClient.waitForEvent('initialized')
.then(() => debugClient.setExceptionBreakpointsRequest({ filters: ['uncaught'] }))
.then(() => debugClient.configurationDoneRequest());
}
}
await Promise.all([
debugClient.configurationSequence(),
setBreakpointFilter(),
debugClient.launch(buildLauncArgs('sampleWithAssertEx.py', false)),
waitToStopDueToException(),
debugClient.assertStoppedLocation('exception', pauseLocation)
]);
});
test('Test multi-threaded debugging', async function () {
if (debuggerType !== 'python') {
// See GitHub issue #1250
Expand Down
1 change: 1 addition & 0 deletions src/test/pythonFiles/debugging/sampleWithAssertEx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assert False