Skip to content

Commit

Permalink
Properly handle exception in internal_set_expression_json
Browse files Browse the repository at this point in the history
  • Loading branch information
lukejriddle committed Mar 27, 2024
1 parent 08ec910 commit da83c33
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 7 additions & 8 deletions _pydevd_bundle/pydevd_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,8 +1313,8 @@ def internal_evaluate_expression(dbg, seq, thread_id, frame_id, expression, is_e
dbg.writer.add_command(cmd)


def _set_expression_response(py_db, request, result, error_message):
body = pydevd_schema.SetExpressionResponseBody(result='', variablesReference=0)
def _set_expression_response(py_db, request, error_message):
body = pydevd_schema.SetExpressionResponseBody(value='')
variables_response = pydevd_base_schema.build_response(request, kwargs={
'body':body, 'success':False, 'message': error_message})
py_db.writer.add_command(NetCommand(CMD_RETURN, 0, variables_response, is_json=True))
Expand All @@ -1333,18 +1333,17 @@ def internal_set_expression_json(py_db, request, thread_id):

frame = py_db.find_frame(thread_id, frame_id)
exec_code = '%s = (%s)' % (expression, value)
result = pydevd_vars.evaluate_expression(py_db, frame, exec_code, is_exec=True)
is_error = isinstance(result, ExceptionOnEvaluate)

if is_error:
_set_expression_response(py_db, request, result, error_message='Error executing: %s' % (exec_code,))
try:
pydevd_vars.evaluate_expression(py_db, frame, exec_code, is_exec=True)
except (Exception, KeyboardInterrupt):
_set_expression_response(py_db, request, error_message='Error executing: %s' % (exec_code,))
return

# Ok, we have the result (could be an error), let's put it into the saved variables.
frame_tracker = py_db.suspended_frames_manager.get_frame_tracker(thread_id)
if frame_tracker is None:
# This is not really expected.
_set_expression_response(py_db, request, result, error_message='Thread id: %s is not current thread id.' % (thread_id,))
_set_expression_response(py_db, request, error_message='Thread id: %s is not current thread id.' % (thread_id,))
return

# Now that the exec is done, get the actual value changed to return.
Expand Down
2 changes: 0 additions & 2 deletions _pydevd_bundle/pydevd_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,6 @@ def method():
raise t.exc[1].with_traceback(t.exc[2])
else:
Exec(compiled, updated_globals, updated_locals)
except Exception as e:
pydev_log.exception(e)
finally:
# Update the globals even if it errored as it may have partially worked.
update_globals_and_locals(updated_globals, initial_globals, frame)
Expand Down

0 comments on commit da83c33

Please sign in to comment.