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

Xonsh throws exceptions on initialization only when carapace is added to the run control #1068

Open
2 of 13 tasks
JeffMelton opened this issue Dec 29, 2024 · 6 comments
Open
2 of 13 tasks
Labels
bug Something isn't working darwin fund Fundable with polar.sh xonsh

Comments

@JeffMelton
Copy link

JeffMelton commented Dec 29, 2024

Current Behavior

After adding exec($(carapace _carapace)) to ~/.config/xonsh/rc.xsh, Xonsh throws exceptions on initialization (examples with minimal traceback below). Happy to bring more detail if needed.

Expected Behavior

Xonsh should initialize without exceptions when carapace is added to the run control.

Steps To Reproduce

To try and track down what was happening, I added echo statements — this is <whatever the file is> — to the top of my Bash and Zsh run control files. My login shell is Zsh, but I do not use it — there's nothing in the run control file except the echo. All the examples below are run from iTerm2 profiles dedicated to the shell indicated.

Examples with Bash, Zsh, and Elvish run control files available:

From Xonsh:

this is bashrc
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
  File "<string>", line 3
    get-env () { echo "${!1}"; } # this looks like Elvish, but I'm not getting a debug print statement from my `rc.elv`
               ^
SyntaxError: invalid syntax
syntax error in xonsh run control file '/Users/j0m0aam/.config/xonsh/rc.xsh': invalid syntax (<string>, line 3)

~

From Zsh:

~ % xonsh
zsh: command not found: xonsh 
~ % ~/.local/xonsh-env/bin/xonsh
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
  File "<string>", line 3
    get-env () { echo "${(P)1}"; }
               ^
SyntaxError: invalid syntax
syntax error in xonsh run control file '<my home dir>/.config/xonsh/rc.xsh': invalid syntax (<string>, line 3)


~~ % ~/.local/xonsh-env/bin/xonsh --no-rc
~ @

Examples without Bash, Zsh, and Elvish run control files available:

From Xonsh:

xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
  File "<string>", line 3
    get-env () { echo "${!1}"; }
               ^
SyntaxError: invalid syntax
syntax error in xonsh run control file '<my home dir>/.config/xonsh/rc.xsh': invalid syntax (<string>, line 3)

From Zsh:*

 ~ % ~/.local/xonsh-env/bin/xonsh
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
  File "<string>", line 3
    get-env () { echo "${(P)1}"; }
               ^
SyntaxError: invalid syntax
syntax error in xonsh run control file '<my home dir>/.config/xonsh/rc.xsh': invalid syntax (<string>, line 3)


~
❯
 ~ % ~/.local/xonsh-env/bin/xonsh --no-rc
 ~ @

Version

No response

OS

  • Darwin
  • Linux
  • Termux
  • Windows

Shell

  • Bash
  • Cmd
  • Elvish
  • Fish
  • Nushell
  • Oil
  • Powershell
  • Xonsh
  • Zsh

Anything else?

No response

Polar

Fund with Polar
@JeffMelton JeffMelton added bug Something isn't working fund Fundable with polar.sh labels Dec 29, 2024
@JeffMelton JeffMelton changed the title <title>Xonsh throws exceptions on initialization only when carapace is added to the run control Xonsh throws exceptions on initialization only when carapace is added to the run control Dec 29, 2024
@rsteube
Copy link
Member

rsteube commented Dec 29, 2024

Looks like the detection isn't working. It's a simple check using the parent process names.

Do you still get the exceptions with:

# ~/.config/xonsh/rc.xsh
exec($(carapace _carapace xonsh))

@JeffMelton
Copy link
Author

Looks like the detection isn't working. It's a simple check using the parent process names.

Do you still get the exceptions with:

# ~/.config/xonsh/rc.xsh

exec($(carapace _carapace xonsh))

Nope, that works as expected. 👍 That's good enough for me. Thank you (and thanks for making carapace, et al.).

@JeffMelton
Copy link
Author

A little more information that may be relevant:

I used xonsh-install to set up my environment. It turns out that xonsh-install uses a Bash wrapper to launch Xonsh (see anki-code/xonsh-install #4 and other discussion it links back to). I don't use Xonsh as a login shell — rather, I set up a profile in my terminal emulator to launch the shell command directly. That uses sh -c, so by the time Xonsh launches we're at $SHLVL 2: sh -c 'bash -i $HOME/.local/xonsh-env/bin/xonsh', more or less.

I don't know how carapace tries to detect the shell it's in, but it seems reasonable to suspect that the extra turtles in the stack might be getting in its way a bit.

@rsteube
Copy link
Member

rsteube commented Jan 11, 2025

It just checks the parent process names one by one until it finds one that fits (see here).
LIkely endet up at the bash one and outputted the wrong script.

Nothing fancy, but usually does the job quite fine.
Might give it another thought if traversing further up is really a good idea, but as far as i remember i had a reason for doing it this way 🤔 .

@rsteube
Copy link
Member

rsteube commented Jan 11, 2025

Probably looks similar to this for you as well?:

root@4f709ae6730a / @# ps -fo command
COMMAND
bash
bash
 \_ /bin/bash -i /root/.local/xonsh-env/xbin/xonsh
     \_ /root/.local/xonsh-env/bin/python /root/.local/xonsh-env/bin/xonsh
         \_ ps -fo command

@JeffMelton
Copy link
Author

Yep, that's the stack of turtles this one puts together. 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working darwin fund Fundable with polar.sh xonsh
Projects
None yet
Development

No branches or pull requests

2 participants