Commit 49b0b9c4 authored by Andrey Lisin's avatar Andrey Lisin Committed by intellij-monorepo-bot
Browse files

PY-37120 Python debugger - properly stop on syntax errors (IDEA-CR-51056)

(cherry picked from commit e6280732fc658ed22741ac3cc5ba2535b4979e05)

GitOrigin-RevId: 8208d238308706be3e0dc96f59e7b0acc10efafe
parent 5c7d5fdb
Showing with 37 additions and 3 deletions
+37 -3
...@@ -705,9 +705,15 @@ class NetCommandFactory: ...@@ -705,9 +705,15 @@ class NetCommandFactory:
abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_frame(curr_frame) abs_path_real_path_and_base = get_abs_path_real_path_and_base_from_frame(curr_frame)
if get_file_type(abs_path_real_path_and_base[2]) == PYDEV_FILE: if get_file_type(abs_path_real_path_and_base[2]) == PYDEV_FILE:
# Skip pydevd files. # Syntax errors are a special case in which we don't want to skip the debugger files.
curr_frame = curr_frame.f_back # When a syntax error happens, we stop either in the `execfile` or `_exec` function.
continue exception_info, is_syntax_error = curr_frame.f_locals.get('__exception__'), False
if exception_info:
is_syntax_error = exception_info[0] is SyntaxError
if not is_syntax_error:
# Skip pydevd files.
curr_frame = curr_frame.f_back
continue
my_file = abs_path_real_path_and_base[0] my_file = abs_path_real_path_and_base[0]
......
x x
\ No newline at end of file
...@@ -495,6 +495,11 @@ public class PythonDebuggerTest extends PyEnvTestCase { ...@@ -495,6 +495,11 @@ public class PythonDebuggerTest extends PyEnvTestCase {
addExceptionBreakpoint(fixture, properties); addExceptionBreakpoint(fixture, properties);
} }
private static void createDefaultExceptionBreakpoint(IdeaProjectTestFixture fixture) {
XDebuggerTestUtil.removeAllBreakpoints(fixture.getProject());
XDebuggerTestUtil.setDefaultBreakpointEnabled(fixture.getProject(), PyExceptionBreakpointType.class, true);
}
@Test @Test
public void testExceptionBreakpointOnFirstRaise() { public void testExceptionBreakpointOnFirstRaise() {
runPythonTest(new PyDebuggerTask("/debug", "test_exceptbreak.py") { runPythonTest(new PyDebuggerTask("/debug", "test_exceptbreak.py") {
...@@ -2204,4 +2209,26 @@ public class PythonDebuggerTest extends PyEnvTestCase { ...@@ -2204,4 +2209,26 @@ public class PythonDebuggerTest extends PyEnvTestCase {
} }
}); });
} }
@Test
public void testStopsOnSyntaxError() {
runPythonTest(new PyDebuggerTask("/debug", "test_syntax_error.py") {
@Override
public void before() {
createDefaultExceptionBreakpoint(myFixture);
}
@Override
public void testing() throws Exception {
waitForPause();
try {
resume();
waitForTerminate();
}
catch (AssertionError e) {
if (!e.getMessage().contains("SyntaxError: invalid syntax")) throw e;
}
}
});
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment