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

Starship with the current main branch: KeyError: 'obj' #5441

Closed
SamLukeYes opened this issue May 25, 2024 · 3 comments · Fixed by #5442
Closed

Starship with the current main branch: KeyError: 'obj' #5441

SamLukeYes opened this issue May 25, 2024 · 3 comments · Fixed by #5442

Comments

@SamLukeYes
Copy link

Current Behavior

On the latest git version of xonsh with starship enabled, after successfully capturing a subprocess, it shows the following traceback, and the starship prompt is temporarily gone until the next command is executed.

Traceback (if applicable):

ERROR:root:'obj'
Traceback (most recent call last):
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/prompt/base.py", line 93, in __call__
    toks = self._format_prompt(template=template, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/ptk_shell/formatter.py", line 46, in _format_prompt
    toks = super()._format_prompt(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/prompt/base.py", line 107, in _format_prompt
    tmpl = template() if callable(template) else template
           ^^^^^^^^^^
  File "<stdin>", line 9, in starship_prompt
  File "<stdin>", line 9, in <genexpr>
KeyError: 'obj'
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/prompt/base.py", line 93, in __call__
    toks = self._format_prompt(template=template, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/ptk_shell/formatter.py", line 46, in _format_prompt
    toks = super()._format_prompt(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/prompt/base.py", line 107, in _format_prompt
    tmpl = template() if callable(template) else template
           ^^^^^^^^^^
  File "<stdin>", line 9, in starship_prompt
  File "<stdin>", line 9, in <genexpr>
KeyError: 'obj'
Failed to format prompt `<function starship_prompt at 0x7f72fdebfce0>`-> <class 'KeyError'>:'obj'
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/prompt/base.py", line 93, in __call__
    toks = self._format_prompt(template=template, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/ptk_shell/formatter.py", line 46, in _format_prompt
    toks = super()._format_prompt(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/prompt/base.py", line 107, in _format_prompt
    tmpl = template() if callable(template) else template
           ^^^^^^^^^^
  File "<stdin>", line 9, in starship_prompt
  File "<stdin>", line 9, in <genexpr>
KeyError: 'obj'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/prompt/base.py", line 172, in _failover_template_format
    return template()
           ^^^^^^^^^^
  File "<stdin>", line 9, in starship_prompt
  File "<stdin>", line 9, in <genexpr>
KeyError: 'obj'
ERROR:root:'obj'
Traceback (most recent call last):
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/prompt/base.py", line 93, in __call__
    toks = self._format_prompt(template=template, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/ptk_shell/formatter.py", line 46, in _format_prompt
    toks = super()._format_prompt(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/prompt/base.py", line 107, in _format_prompt
    tmpl = template() if callable(template) else template
           ^^^^^^^^^^
  File "<stdin>", line 18, in starship_rprompt
  File "<stdin>", line 18, in <genexpr>
KeyError: 'obj'
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/prompt/base.py", line 93, in __call__
    toks = self._format_prompt(template=template, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/ptk_shell/formatter.py", line 46, in _format_prompt
    toks = super()._format_prompt(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/prompt/base.py", line 107, in _format_prompt
    tmpl = template() if callable(template) else template
           ^^^^^^^^^^
  File "<stdin>", line 18, in starship_rprompt
  File "<stdin>", line 18, in <genexpr>
KeyError: 'obj'
Failed to format prompt `<function starship_rprompt at 0x7f72fdebfe20>`-> <class 'KeyError'>:'obj'
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/prompt/base.py", line 93, in __call__
    toks = self._format_prompt(template=template, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/ptk_shell/formatter.py", line 46, in _format_prompt
    toks = super()._format_prompt(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/prompt/base.py", line 107, in _format_prompt
    tmpl = template() if callable(template) else template
           ^^^^^^^^^^
  File "<stdin>", line 18, in starship_rprompt
  File "<stdin>", line 18, in <genexpr>
KeyError: 'obj'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/yes/.virtualenvs/xonsh-test/lib/python3.12/site-packages/xonsh/prompt/base.py", line 172, in _failover_template_format
    return template()
           ^^^^^^^^^^
  File "<stdin>", line 18, in starship_rprompt
  File "<stdin>", line 18, in <genexpr>
KeyError: 'obj'

I found this issue when investigating #5003, reproduced and bisected in my Arch Linux container. The first bad commit is 0f25a5a.

Expected Behavior

There shouldn't be any errors after using !(), and the starship prompt should show up as normal afterwards.

xonfig

+-----------------------------+----------------------+
| xonsh                       | 0.16.0.dev111        |
| Git SHA                     | 0f25a5a3             |
| Commit Date                 | May 22 23:45:39 2024 |
| Python                      | 3.12.3               |
| PLY                         | 3.11                 |
| have readline               | True                 |
| prompt toolkit              | 3.0.39               |
| shell type                  | prompt_toolkit       |
| history backend             | json                 |
| pygments                    | 2.18.0               |
| on posix                    | True                 |
| on linux                    | True                 |
| distro                      | arch                 |
| on wsl                      | False                |
| on darwin                   | False                |
| on windows                  | False                |
| on cygwin                   | False                |
| on msys2                    | False                |
| is superuser                | False                |
| default encoding            | utf-8                |
| xonsh encoding              | utf-8                |
| encoding errors             | surrogateescape      |
| xontrib 1                   | vox                  |
| xontrib 2                   | voxapi               |
| RC file 1                   | /home/yes/.xonshrc   |
| UPDATE_OS_ENVIRON           | False                |
| XONSH_CAPTURE_ALWAYS        | False                |
| XONSH_SUBPROC_OUTPUT_FORMAT | stream_lines         |
| THREAD_SUBPROCS             | True                 |
| XONSH_CACHE_SCRIPTS         | True                 |
+-----------------------------+----------------------+

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

@anki-code
Copy link
Member

anki-code commented May 25, 2024

Hey! Nice catch!
The "obj" from jobs was renamed to "proc" here - 0f25a5a#diff-893f3d2e484910a3d1f57b499bdc81bf828ad764af9b7de0a8abb3d4e648d2c7L958
I see no commands to reproduce the issue but I guess starship uses "obj" somewhere.

UPD: here:

https://github.com/starship/starship/blob/86c1312a05116fb404ab6ae90af37f78915f77b8/src/init/starship.xsh#L4-L11

We have two ways: update starship or revert xonsh to "obj". I'm going to revert rename until we will have singleton for jobs to implement backwards compatibility.

@anki-code anki-code changed the title [starship compatibility] xonsh shows traceback after capturing subprocess with !() Starship with the current main branch: KeyError: 'obj' May 25, 2024
@SamLukeYes
Copy link
Author

I see no commands to reproduce the issue but I guess starship uses "obj" somewhere.

Sorry for forgetting to mention that. The command !(echo Nix is nice) we used previously actually triggers this issue right after the expected output. On Arch Linux, I installed the git version of xonsh to a vox environment using pip.

@anki-code
Copy link
Member

anki-code commented May 25, 2024

PR is here. Thanks!

anki-code added a commit that referenced this issue May 25, 2024
### Motivation

Closes #5441

In the nutshell [Starship uses
"obj"](https://github.com/starship/starship/blob/86c1312a05116fb404ab6ae90af37f78915f77b8/src/init/starship.xsh#L4-L11)
so let's revert [the
renaming](0f25a5a#diff-893f3d2e484910a3d1f57b499bdc81bf828ad764af9b7de0a8abb3d4e648d2c7L958)
and will implement backwards compatibility when we switch jobs to
singleton object some day.

## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**

Co-authored-by: a <1@1.1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants