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

pdb: calling registered alias without command raises KeyError #109375

Closed
buermarc opened this issue Sep 13, 2023 · 0 comments
Closed

pdb: calling registered alias without command raises KeyError #109375

buermarc opened this issue Sep 13, 2023 · 0 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@buermarc
Copy link
Contributor

buermarc commented Sep 13, 2023

Bug report

Bug description:

pdb allows to register an alias without a command.
Calling that alias raises an unhandled exception.

$ /tmp/ cat bar.py
breakpoint()
$ /tmp/ python bar.py 
--Return--
> /tmp/bar.py(1)<module>()->None
-> breakpoint()
(Pdb) alias foo
(Pdb) foo
Traceback (most recent call last):
  File "/tmp/bar.py", line 1, in <module>
    breakpoint()
  File "/home/home/.pyenv/versions/3.11.1/lib/python3.11/bdb.py", line 94, in trace_dispatch
    return self.dispatch_return(frame, arg)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/home/.pyenv/versions/3.11.1/lib/python3.11/bdb.py", line 153, in dispatch_return
    self.user_return(frame, arg)
  File "/home/home/.pyenv/versions/3.11.1/lib/python3.11/pdb.py", line 372, in user_return
    self.interaction(frame, None)
  File "/home/home/.pyenv/versions/3.11.1/lib/python3.11/pdb.py", line 435, in interaction
    self._cmdloop()
  File "/home/home/.pyenv/versions/3.11.1/lib/python3.11/pdb.py", line 400, in _cmdloop
    self.cmdloop()
  File "/home/home/.pyenv/versions/3.11.1/lib/python3.11/cmd.py", line 137, in cmdloop
    line = self.precmd(line)
           ^^^^^^^^^^^^^^^^^
  File "/home/home/.pyenv/versions/3.11.1/lib/python3.11/pdb.py", line 473, in precmd
    while args[0] in self.aliases:
          ~~~~^^^
IndexError: list index out of range

The general syntax of alias foo is valid, as it allows to print the alias. However, if there is no command registered, calling it fails.

I am unsure if raising an exception is the wanted behavior here. I think providing an error message which indicates that the current alias is unknown could be more appropriate, e.g.:

$ python /tmp/bar.py
--Return--
> /tmp/bar.py(1)<module>()->None
-> breakpoint()
(Pdb) alias foo
*** Unkown alias. To create an alias see 'help alias'

A solution could be to add an additional check to catch cases where one tries to register an alias without a command.

CPython versions tested on:

3.10, 3.11, CPython main branch

Operating systems tested on:

Linux

Linked PRs

@buermarc buermarc added the type-bug An unexpected behavior, bug, or error label Sep 13, 2023
buermarc added a commit to buermarc/cpython that referenced this issue Sep 13, 2023
An unkown alias without a given command should not register a new alias.
buermarc added a commit to buermarc/cpython that referenced this issue Sep 13, 2023
An unkown alias without a given command should not register a new alias.
buermarc added a commit to buermarc/cpython that referenced this issue Sep 13, 2023
An unkown alias without a given command should not register a new alias.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 14, 2023
…ciated command (pythonGH-109376)

(cherry picked from commit 68a6f21)

Co-authored-by: buermarc <44375277+buermarc@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 14, 2023
…ciated command (pythonGH-109376)

(cherry picked from commit 68a6f21)

Co-authored-by: buermarc <44375277+buermarc@users.noreply.github.com>
@iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Sep 14, 2023
vstinner pushed a commit that referenced this issue Sep 22, 2023
…ociated command (GH-109376) (#109430)

gh-109375: Fix bug where pdb registers an alias without an associated command (GH-109376)
(cherry picked from commit 68a6f21)

Co-authored-by: buermarc <44375277+buermarc@users.noreply.github.com>
Yhg1s pushed a commit that referenced this issue Oct 2, 2023
…ociated command (GH-109376) (#109429)

gh-109375: Fix bug where pdb registers an alias without an associated command (GH-109376)
(cherry picked from commit 68a6f21)

Co-authored-by: buermarc <44375277+buermarc@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants