From 8b67af843ffe5b797c5c9e4dafaf3fb859c452a8 Mon Sep 17 00:00:00 2001 From: Mathias Fussenegger Date: Fri, 6 Mar 2026 15:44:36 +0100 Subject: [PATCH] Show error message on evaluate also for hover context If a client sends an evaluate command with context=hover and if the expression fails, the client received an error with the message "Exception occurred during evaluation" This wasn't very helpful. This changes the logic to treat `hover` just like `watch` in the error case to send back `eval_result.result`. That contains the message of the exception which is typically more useful. --- src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py b/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py index 64ac454f2..8810f7f14 100644 --- a/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py +++ b/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py @@ -1214,11 +1214,8 @@ def __create_frame(): eval_result = pydevd_vars.evaluate_expression(py_db, frame, expression, is_exec=False) is_error = isinstance_checked(eval_result, ExceptionOnEvaluate) if is_error: - if context == "hover": # In a hover it doesn't make sense to do an exec. - _evaluate_response(py_db, request, result="", error_message="Exception occurred during evaluation.") - return - elif context == "watch": - # If it's a watch, don't show it as an exception object, rather, format + if context in ["watch", "hover"]: + # If it's hover or watch, don't show it as an exception object, rather, format # it and show it as a string (with success=False). msg = "%s: %s" % ( eval_result.result.__class__.__name__,