diff --git a/news/2 Fixes/1194.md b/news/2 Fixes/1194.md new file mode 100644 index 000000000000..8301b2c8d5dd --- /dev/null +++ b/news/2 Fixes/1194.md @@ -0,0 +1 @@ +Ensure debugger breaks on `assert` failures. diff --git a/src/client/debugger/PythonProcessCallbackHandler.ts b/src/client/debugger/PythonProcessCallbackHandler.ts index 2b18c62ee804..da5d32359577 100644 --- a/src/client/debugger/PythonProcessCallbackHandler.ts +++ b/src/client/debugger/PythonProcessCallbackHandler.ts @@ -259,7 +259,7 @@ export class PythonProcessCallbackHandler extends EventEmitter { return; } - if (typeName && desc) { + if (typeName || desc) { let ex: IPythonException = { TypeName: typeName, Description: desc diff --git a/src/test/debugger/misc.test.ts b/src/test/debugger/misc.test.ts index 995be0db817a..64efb7f6f405 100644 --- a/src/test/debugger/misc.test.ts +++ b/src/test/debugger/misc.test.ts @@ -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 { + 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 diff --git a/src/test/pythonFiles/debugging/sampleWithAssertEx.py b/src/test/pythonFiles/debugging/sampleWithAssertEx.py new file mode 100644 index 000000000000..2cfffa40db4b --- /dev/null +++ b/src/test/pythonFiles/debugging/sampleWithAssertEx.py @@ -0,0 +1 @@ +assert False