Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1109,10 +1109,17 @@ def on_scopes_request(self, py_db, request):
frame_id = request.arguments.frameId

variables_reference = frame_id
scopes = [
Scope("Locals", ScopeRequest(int(variables_reference), "locals"), False, presentationHint="locals"),
Scope("Globals", ScopeRequest(int(variables_reference), "globals"), False),
]
try:
scopes = [
Scope("Locals", ScopeRequest(int(variables_reference), "locals"), False, presentationHint="locals"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot generated:
except Exception is too broad. The PR description identifies ValueError from int() as the failure mode — catch (ValueError, TypeError) instead. The current catch will silently swallow any future bug in Scope() or ScopeRequest() constructors (e.g., AttributeError, KeyError), making those bugs invisible. All three technical reviewers flagged this independently. [unverified]

[verified]

Scope("Globals", ScopeRequest(int(variables_reference), "globals"), False),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot generated:
The except block has no logging. When this triggers in production, there's zero diagnostic trail — the user sees an empty Variables panel with no explanation. Add at minimum pydev_log.info('Invalid frameId %r in scopes request', variables_reference) so developers can trace why variables aren't showing. The Advocate notes the codebase has precedent for logging in exception handlers (e.g., line 534 uses pydev_log.exception). [unverified]

[verified]

]
except (ValueError, TypeError):
pydev_log.info("Failed to create scopes for frame id: %s", frame_id)
scopes = []
except Exception:
pydev_log.exception("Failed to create scopes for frame id: %s", frame_id)
scopes = []
body = ScopesResponseBody(scopes)
scopes_response = pydevd_base_schema.build_response(request, kwargs={"body": body})
return NetCommand(CMD_RETURN, 0, scopes_response, is_json=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
def test_on_scopes_request_with_valid_frame_id():
from _pydevd_bundle._debug_adapter import pydevd_schema, pydevd_base_schema
from _pydevd_bundle.pydevd_process_net_command_json import PyDevJsonCommandProcessor

processor = PyDevJsonCommandProcessor(pydevd_base_schema.from_json)
request = pydevd_schema.ScopesRequest(pydevd_schema.ScopesArguments(frameId=1))

result = processor.on_scopes_request(None, request)
response = result.as_dict

assert response["success"] is True
scopes = response["body"]["scopes"]
assert len(scopes) == 2
assert scopes[0]["name"] == "Locals"
assert scopes[0]["presentationHint"] == "locals"
assert scopes[1]["name"] == "Globals"


def test_on_scopes_request_with_invalid_frame_id():
from _pydevd_bundle._debug_adapter import pydevd_schema, pydevd_base_schema
from _pydevd_bundle.pydevd_process_net_command_json import PyDevJsonCommandProcessor

processor = PyDevJsonCommandProcessor(pydevd_base_schema.from_json)
request = pydevd_schema.ScopesRequest(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot generated:
-26

frameId="not_a_number" tests a scenario that likely can't occur via the DAP protocol (which defines frameId as integer). The more realistic failure mode is a valid integer that references a stale/dead frame (e.g., frameId=999999). Consider adding a test for that case — it would exercise a more likely production failure path. [unverified]

[verified]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

999999 is a valid int, so it wouldn't exercise what we're preventing here, which would be a non-integer value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specific issue we've seen is that the client can send a scopes request using a DAP id that corresponds to a thread instead of a frame. The DAP to id translation converts that to something like pid_1996270_id_140192610058896 which raises an exception when passed to int().

pydevd_schema.ScopesArguments(frameId="not_a_number")
)

result = processor.on_scopes_request(None, request)
response = result.as_dict

assert response["success"] is True
assert response["body"]["scopes"] == []
Loading