Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError in NetCommandFactoryJson.make_get_thread_stack_message() #928

Merged

Conversation

jgru
Copy link
Contributor

@jgru jgru commented May 8, 2022

Dear maintainers,

I experienced the following error using debugpy with Python3 in Version 3.9.2 both on macOS 12.3.1 and Debian Bookworm.
The issue came up when using Emacs' dap-mode.

Traceback (most recent call last):
  File "/home/username/.local/lib/python3.9/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 252, in _on_run
    self.process_net_command_json(self.py_db, json_contents)
  File "/home/username/.local/lib/python3.9/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command_json.py", line 193, in process_net_command_json
    cmd = on_request(py_db, request)
  File "/home/username/.local/lib/python3.9/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command_json.py", line 953, in on_stacktrace_request
    self.api.request_stack(py_db, request.seq, thread_id, fmt=fmt, start_frame=start_frame, levels=levels)
  File "/home/username/.local/lib/python3.9/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_api.py", line 206, in request_stack
    if internal_get_thread_stack.can_be_executed_by(get_current_thread_id(threading.current_thread())):
  File "/home/username/.local/lib/python3.9/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 654, in can_be_executed_by
    self._cmd = py_db.cmd_factory.make_get_thread_stack_message(
  File "/home/username/.local/lib/python3.9/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_net_command_factory_json.py", line 284, in make_get_thread_stack_message
    end = min(start + levels, total_frames)
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

The error occured with the current HEAD of main-branch (commit 0a40cab) and with the version 1.6.0 hosted on PyPi.
The cause of it seems to be that start_frame is used for addition in order to determine a stackframe number, although it is was None.

This PR fixes the issue.

Thanks already in advance for considering this small contribution.

Best regards,
jgru

@fabioz
Copy link
Collaborator

fabioz commented May 12, 2022

@jgru thanks for the pull request (sorry for the delay in getting back to you).

I think that a better approach could be not letting the None get there in the first place (it should be an int at that point, not Optional[int]).

So, the fix should probably be changing

_pydevd_bundle.pydevd_process_net_command_json.PyDevJsonCommandProcessor.on_stacktrace_request

Where it should check startFrame and levels for None and change to 0 if needed.

@jgru jgru force-pushed the fix-typeerror-in-make_get_thread_stack_message branch from 3a19b12 to 1f84334 Compare May 13, 2022 05:32
@jgru
Copy link
Contributor Author

jgru commented May 13, 2022

@jgru thanks for the pull request (sorry for the delay in getting back to you).

Thanks for getting back to me.

So, the fix should probably be changing
_pydevd_bundle.pydevd_process_net_command_json.PyDevJsonCommandProcessor.on_stacktrace_request
Where it should check startFrame and levels for None and change to 0 if needed.

I reverted the initial change and introduced two predicates in _pydevd_bundle.pydevd_process_net_command_json.PyDevJsonCommandProcessor.on_stacktrace_request to ensure that they will never be None. Hope this change is fine now.

Best regards,
jgru

@sonarcloud
Copy link

sonarcloud bot commented May 13, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@fabioz fabioz merged commit 78b030f into microsoft:main May 19, 2022
@fabioz
Copy link
Collaborator

fabioz commented May 19, 2022

Seems good to me. Just merged.

Thank you very much for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants