PyDev.Debugger icon indicating copy to clipboard operation
PyDev.Debugger copied to clipboard

Handle exception thrown when executing invalid expression

Open lukejriddle opened this issue 4 months ago • 3 comments

If an invalid expression is evaluated, the attempt to exec said expression results in an exception. Since the code omits an except clause and only does try finally, the exception is not properly discarded without a return, break, or continue statement: reference.

This resulted in the debugger hanging indefinitely when an invalid expression was evaluated. The exception would show in the console, but the stepping/continuing would stop working.

~This PR fixes this issue by adding the except clause and logging the exception. This allows the debugger to continue executing.~

This PR fixes this issue by properly handling the exception in the calling method (see comments below)

lukejriddle avatar Mar 27 '24 21:03 lukejriddle

I should note that this only happens when internal_set_expression_json is called -- as part of a setExpression DAP call -- and that this issue doesn't occur when internal_evaluate_expression_json is called -- from the repl.

This is because the former expects a return value from evaluate_expression, but that function will never return anything since is_exec=True. This results in the error check always failing. The latter properly wraps it in a try except.

lukejriddle avatar Mar 27 '24 22:03 lukejriddle

It also appears that if is_error were ever actually true, which it never will be since the function doesn't return anything, there'd be a runtime exception. Creating a SetExpressionResponseBody is done improperly; it expects value in the constructor.

Same for these lines. I'm guessing this condition is never true, which makes sense from the comment.

lukejriddle avatar Mar 27 '24 22:03 lukejriddle

Added a new commit to address the above ^

lukejriddle avatar Mar 27 '24 23:03 lukejriddle