microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.76k stars 29.1k forks source link

Terminal Shell Integration Error -- command not found #157851

Closed branic closed 2 years ago

branic commented 2 years ago

Type: Bug

After upgrading to 1.70.1 the integrated terminal (with shell integration enabled) is generating the following error whenever a terminal is launched and also after every command.

bash: [[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && chruby_auto: command not found...

This appears to be related to #157189 as the 1.70.1 version was the first to include the fix for that issue.

The error is the same as what trap -p DEBUG is set to. This seems like the command trying to be run is a string and is not being parsed like there are arguments.

$ trap -p DEBUG
trap -- '[[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && chruby_auto' DEBUG

VS Code version: Code 1.70.1 (6d9b74a70ca9c7733b29f0456fd8195364076dda, 2022-08-10T06:09:15.055Z) OS version: Linux x64 5.18.15-200.fc36.x86_64 Modes:

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz (12 x 2700)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: disabled_software
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled| |Load (avg)|2, 2, 1| |Memory (System)|62.56GB (3.04GB free)| |Process Argv|--unity-launch --crash-reporter-id 57fdd0a5-4103-4bed-9134-70c1dcd69cc9| |Screen Reader|no| |VM|0%| |DESKTOP_SESSION|gnome-xorg| |XDG_CURRENT_DESKTOP|GNOME| |XDG_SESSION_DESKTOP|gnome-xorg| |XDG_SESSION_TYPE|x11|
Extensions (38) Extension|Author (truncated)|Version ---|---|--- asciidoctor-vscode|asc|2.9.8 scratchpads|bue|0.0.7 solargraph|cas|0.23.0 vscode-markdownlint|Dav|0.47.0 ansible-vault|dho|0.1.3 docs-markdown|doc|0.2.113 githistory|don|0.6.19 gitlens|eam|12.1.2 json-tools|eri|1.0.2 opensslutils|ffa|1.1.1 shell-format|fox|7.2.2 gc-excelviewer|Gra|4.2.55 todo-tree|Gru|0.0.215 rest-client|hum|0.25.0 vscode-jmespath|jos|0.0.6 bash-ide-vscode|mad|1.14.0 git-graph|mhu|1.30.0 vscode-docker|ms-|1.22.1 python|ms-|2022.12.0 vscode-pylance|ms-|2022.8.20 remote-containers|ms-|0.241.3 remote-ssh|ms-|0.84.0 remote-ssh-edit|ms-|0.80.0 cpptools|ms-|1.11.5 ruby|reb|0.28.1 ansible|red|0.11.29 vscode-commons|red|0.0.6 vscode-yaml|red|1.9.1 bash-debug|rog|0.3.9 rufo-vscode|sil|0.0.3 code-spell-checker|str|2.5.4 shellcheck|tim|0.19.6 pdf|tom|1.2.0 vscode-icons|vsc|11.15.0 vim|vsc|1.23.2 jinja|who|0.0.8 vscode-ruby|win|0.28.0 markdown-all-in-one|yzh|3.4.3 (2 theme extensions excluded)
A/B Experiments ``` vsliv368cf:30146710 vsreu685:30147344 python383:30185418 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 pythonvspyl392:30443607 vserr242cf:30382550 pythontb:30283811 vsjup518:30340749 pythonptprofiler:30281270 vshan820:30294714 vstes263cf:30335440 vscorecescf:30445987 pythondataviewer:30285071 vscod805:30301674 binariesv615:30325510 bridge0708:30335490 bridge0723:30353136 vsaa593cf:30376535 pythonvs932:30410667 wslgetstarted:30449410 cppdebug:30492333 vscaat:30438848 pylanb8912cf:30529770 vsclangdf:30486550 c4g48928:30535728 d7fjc500:30543455 dsvsc012cf:30540253 ```
TechDufus commented 2 years ago

Bump. I'm also getting this.

Tyriar commented 2 years ago

@meganrogge the fix for https://github.com/microsoft/vscode/issues/157189 may not have worked for all cases?

meganrogge commented 2 years ago

Okay so we'll disable if there's an error

branic commented 2 years ago

@meganrogge @Tyriar I've been looking into this a bit more and the pieces that were added are good, but they just don't go quite far enough. The replacements that were added leave the ' character in place at the beginning and end. Adjusting the line that strips the DEBUG to include the space before it and then adding lines to remove the ' allow the function to work as expected in my testing.

         if [[ "$__vsc_dbg_trap" =~ .*\[\[.* ]]; then
                 #HACK - is there a better way to do this?
                 __vsc_dbg_trap=${__vsc_dbg_trap#'trap -- '*}
                 __vsc_dbg_trap=${__vsc_dbg_trap%' DEBUG'}
                 __vsc_dbg_trap=${__vsc_dbg_trap#"'"*}
                 __vsc_dbg_trap=${__vsc_dbg_trap%"'"}
         else

Stripping the ' character could be done in the two commands, but I think adding two additional lines to strip is safer as it seems to me that it would be possible to have a trap without surrounding ', but that may not be the case.

branic commented 2 years ago

A little bit more playing around and and even for single commands trap -p adds the ' characters.

For example setting the DEBUG trap to:

trap echo DEBUG

then trap -p DEBUG will return

trap -- 'echo' DEBUG

This means that this code block:

    __vsc_dbg_trap="$(trap -p DEBUG)"
    if [[ "$__vsc_dbg_trap" =~ .*\[\[.* ]]; then
        #HACK - is there a better way to do this?
        __vsc_dbg_trap=${__vsc_dbg_trap#'trap -- '*}
        __vsc_dbg_trap=${__vsc_dbg_trap%'DEBUG'}
    else
        __vsc_dbg_trap="$(trap -p DEBUG | cut -d' ' -f3 | tr -d \')"
    fi

could be simplified to

    __vsc_dbg_trap="$(trap -p DEBUG)"
    __vsc_dbg_trap=${__vsc_dbg_trap#"trap -- '"*}
    __vsc_dbg_trap=${__vsc_dbg_trap%" 'DEBUG"}
branic commented 2 years ago

Based on the above comments, I don't think #157945 is the correct fix.

meganrogge commented 2 years ago

@branic thanks for looking into this and your comment above makes sense

rzhao271 commented 2 years ago

What are some verification steps for this issue?

vscodenpa commented 2 years ago

This bug has been fixed in the latest release of VS Code Insiders!

@branic, you can help us out by commenting /verified if things are now working as expected.

If things still don't seem right, please ensure you're on version 9529e11f6481ae53bba821b05e34549491b9415e of Insiders (today's or later - you can use Help: About in the command palette to check), and leave a comment letting us know what isn't working as expected.

Happy Coding!

TylerLeonhardt commented 2 years ago

@meganrogge since it's Friday of endgame, can we get some verification steps?

meganrogge commented 2 years ago

this isn't working for me

meganrogge commented 2 years ago

actually, this is working for me.

add trap -- '[[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]] && __function__' DEBUG where __function__ is a command that is known in your env to your .bash_profile.

You'll know it's one that can work because you should be able to run in by itself in the terminal without errors.

Verify that shell integration still works and your command runs

connor4312 commented 2 years ago

I think this is the expected outcome:

image