zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
48.95k stars 2.95k forks source link

Failed to parse output of `env` command in login shell #16171

Closed oleynikandrey closed 1 month ago

oleynikandrey commented 2 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

Zed 0.147.2 became broken somehow. It could not install gopls because it was unable to parse the output of the env command.

Environment

Apple M1 Max Sonoma Version 14.6.1 (23G93) Shell ZSH (oh-my-zsh)

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your Zed.log file to this issue.

Zed.log

2024-08-13T17:35:52.427467Z [INFO] ========== starting zed ==========
2024-08-13T17:35:52.428136Z [INFO] Opening main db
2024-08-13T17:35:52.429315Z [INFO] Using git binary path: Some("/Applications/Zed.app/Contents/MacOS/git")
2024-08-13T17:35:52.554879Z [INFO] extensions updated. loading 2, reloading 0, unloading 0
2024-08-13T17:35:52.587512Z [INFO] Opening main db
2024-08-13T17:35:52.593106Z [INFO] building git repository, `.git` path in the worktree: ".git"
2024-08-13T17:35:52.634528Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.63472Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.634805Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.634862Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.635038Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.635167Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.635227Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.635297Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.635521Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.635616Z [INFO] Opening main db
2024-08-13T17:35:52.63573Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.63595Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.636468Z [INFO] set status on client 0: Authenticating
2024-08-13T17:35:52.63901Z [INFO] Opening main db
2024-08-13T17:35:52.651181Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.657931Z [INFO] set status on client 204564: Connecting
2024-08-13T17:35:52.673086Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.676526Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.677312Z [INFO] Initializing default prettier with plugins {}
2024-08-13T17:35:52.677418Z [INFO] starting language servers for Go: gopls
2024-08-13T17:35:52.677486Z [INFO] starting language server "gopls", path: "/Users/user/repoes/go", id: 1
2024-08-13T17:35:52.677663Z [INFO] Initializing default prettier with plugins {}
2024-08-13T17:35:52.677729Z [INFO] starting language servers for Go: gopls
2024-08-13T17:35:52.694455Z [INFO] Initializing default prettier with plugins {}
2024-08-13T17:35:52.694552Z [INFO] starting language servers for Go: gopls
2024-08-13T17:35:52.694746Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.713925Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.720685Z [INFO] Initializing default prettier with plugins {}
2024-08-13T17:35:52.720795Z [INFO] starting language servers for Go: gopls
2024-08-13T17:35:52.735424Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.788324Z [INFO] Initializing default prettier with plugins {}
2024-08-13T17:35:52.788432Z [INFO] starting language servers for Go: gopls
2024-08-13T17:35:52.805038Z [WARN] request completed with error: unknown error
2024-08-13T17:35:52.924331Z [ERROR] failed to determine load login shell environment in "/Users/user/repoes/go"

Caused by:
    failed to parse output of `env` command in login shell:
2024-08-13T17:35:53.056467Z [ERROR] failed to determine load login shell environment in "/Users/user/repoes/go"

Caused by:
    failed to parse output of `env` command in login shell:
2024-08-13T17:35:53.056923Z [ERROR] no cached binary
2024-08-13T17:35:53.05701Z [ERROR] failed to start language server "gopls": cannot install gopls
2024-08-13T17:35:53.057075Z [ERROR] server stderr: Some("")
2024-08-13T17:35:53.05714Z [INFO] retrying installation of language server "gopls" in 1s
2024-08-13T17:35:53.066053Z [INFO] connected to rpc endpoint https://collab.zed.dev/rpc
2024-08-13T17:35:53.64065Z [INFO] add connection to peer
2024-08-13T17:35:53.641181Z [INFO] add_connection;
2024-08-13T17:35:53.64168Z [INFO] waiting for server hello
2024-08-13T17:35:53.642231Z [INFO] got server hello
2024-08-13T17:35:53.642491Z [INFO] set status to connected (connection id: ConnectionId { owner_id: 0, id: 0 }, peer id: PeerId { owner_id: 482, id: 420122 })
2024-08-13T17:35:53.642986Z [INFO] set status on client 204564: Connected { peer_id: PeerId { owner_id: 482, id: 420122 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-08-13T17:35:54.102711Z [ERROR] no cached binary
2024-08-13T17:35:54.103045Z [INFO] About to spawn test binary
2024-08-13T17:35:54.10329Z [WARN] test binary failed to launch
2024-08-13T17:35:54.103519Z [WARN] test binary check failed
2024-08-13T17:35:54.103745Z [INFO] beginning to reinstall server
2024-08-13T17:35:54.103999Z [INFO] deleting server container
2024-08-13T17:35:54.104531Z [INFO] starting language server "gopls", path: "/Users/user/repoes/go", id: 2
2024-08-13T17:35:54.238308Z [ERROR] failed to determine load login shell environment in "/Users/user/repoes/go"

Caused by:
    failed to parse output of `env` command in login shell:
2024-08-13T17:35:54.360228Z [ERROR] failed to determine load login shell environment in "/Users/user/repoes/go"

Caused by:
    failed to parse output of `env` command in login shell:
2024-08-13T17:35:54.360696Z [ERROR] no cached binary
2024-08-13T17:35:54.360774Z [ERROR] failed to start language server "gopls": cannot install gopls
2024-08-13T17:35:54.360838Z [ERROR] server stderr: Some("")
2024-08-13T17:35:54.360898Z [INFO] retrying installation of language server "gopls" in 1s
2024-08-13T17:35:55.395375Z [ERROR] no cached binary
2024-08-13T17:35:55.39573Z [INFO] About to spawn test binary
2024-08-13T17:35:55.395971Z [WARN] test binary failed to launch
2024-08-13T17:35:55.396201Z [WARN] test binary check failed
2024-08-13T17:35:55.396427Z [INFO] beginning to reinstall server
2024-08-13T17:35:55.396687Z [INFO] deleting server container
2024-08-13T17:35:55.397235Z [INFO] starting language server "gopls", path: "/Users/user/repoes/go", id: 3
2024-08-13T17:35:55.543385Z [ERROR] failed to determine load login shell environment in "/Users/user/repoes/go"

Caused by:
    failed to parse output of `env` command in login shell:
2024-08-13T17:35:55.660992Z [ERROR] failed to determine load login shell environment in "/Users/user/repoes/go"

Caused by:
    failed to parse output of `env` command in login shell:
2024-08-13T17:35:55.661464Z [ERROR] no cached binary
2024-08-13T17:35:55.661546Z [ERROR] failed to start language server "gopls": cannot install gopls
2024-08-13T17:35:55.661608Z [ERROR] server stderr: Some("")
2024-08-13T17:35:55.661666Z [INFO] retrying installation of language server "gopls" in 1s
2024-08-13T17:35:56.703418Z [ERROR] no cached binary
2024-08-13T17:35:56.703877Z [INFO] About to spawn test binary
2024-08-13T17:35:56.704248Z [WARN] test binary failed to launch
2024-08-13T17:35:56.704565Z [WARN] test binary check failed
2024-08-13T17:35:56.704847Z [INFO] beginning to reinstall server
2024-08-13T17:35:56.70506Z [INFO] deleting server container
2024-08-13T17:35:56.705542Z [INFO] starting language server "gopls", path: "/Users/user/repoes/go", id: 4
2024-08-13T17:35:56.850852Z [ERROR] failed to determine load login shell environment in "/Users/user/repoes/go"

Caused by:
    failed to parse output of `env` command in login shell:
2024-08-13T17:35:56.969945Z [ERROR] failed to determine load login shell environment in "/Users/user/repoes/go"

Caused by:
    failed to parse output of `env` command in login shell:
2024-08-13T17:35:56.970444Z [ERROR] no cached binary
2024-08-13T17:35:56.970519Z [ERROR] failed to start language server "gopls": cannot install gopls
2024-08-13T17:35:56.97058Z [ERROR] server stderr: Some("")
2024-08-13T17:35:56.97064Z [INFO] retrying installation of language server "gopls" in 1s
2024-08-13T17:35:58.011576Z [ERROR] no cached binary
2024-08-13T17:35:58.012151Z [INFO] About to spawn test binary
2024-08-13T17:35:58.012505Z [WARN] test binary failed to launch
2024-08-13T17:35:58.012835Z [WARN] test binary check failed
2024-08-13T17:35:58.013163Z [INFO] beginning to reinstall server
2024-08-13T17:35:58.013544Z [INFO] deleting server container
2024-08-13T17:35:58.014486Z [INFO] starting language server "gopls", path: "/Users/user/repoes/go", id: 5
2024-08-13T17:35:58.163867Z [ERROR] failed to determine load login shell environment in "/Users/user/repoes/go"

Caused by:
    failed to parse output of `env` command in login shell:
2024-08-13T17:35:58.280203Z [ERROR] failed to determine load login shell environment in "/Users/user/repoes/go"

Caused by:
    failed to parse output of `env` command in login shell:
2024-08-13T17:35:58.28067Z [ERROR] no cached binary
2024-08-13T17:35:58.280753Z [ERROR] failed to start language server "gopls": cannot install gopls
2024-08-13T17:35:58.280815Z [ERROR] server stderr: Some("")
2024-08-13T17:35:58.280874Z [ERROR] Hit 4 reinstallation attempts for "gopls"

mrnugget commented 2 months ago

Hey! Did it work before? What changed? Did you change your shell environment somehow? With which Zed version did it work?

oleynikandrey commented 2 months ago

I have just installed it and played with it for a while. At first, it seemed to be working, but I cannot say for sure.

mrnugget commented 1 month ago

What do you get when you run the following in a terminal?

env -i HOME="$HOME" /bin/zsh -i -l -c 'cd ~/; /usr/bin/env' | grep PATH
oleynikandrey commented 1 month ago

I'm getting the following error

➜  ~ env -i HOME="$HOME" /bin/zsh -i -l -c 'cd ~/; /usr/bin/env' | grep PATH
Could not open a connection to your authentication agent.
oleynikandrey commented 1 month ago

I found the cause of the problem. I had the zellij command at the bottom of my .zshrc file, and it was interfering with the command that was used to get the value of the PATH variable.

if [[ -z "$ZELLIJ" && -z "$ZELLIJ_DISABLED" ]]; then
    if [[ "$ZELLIJ_AUTO_ATTACH" == "true" ]]; then
        zellij attach -c
    else
        zellij
    fi

    if [[ "$ZELLIJ_AUTO_EXIT" == "true" ]]; then
        exit
    fi
fi
mrnugget commented 1 month ago

Huh! Interesting. So if you remove that it works?

oleynikandrey commented 1 month ago

Yes

mrnugget commented 1 month ago

You could try modifying the script the check whether stdout/stdin/stderr are a terminal and only then start zellij:

if [[ -z "$ZELLIJ" ]] && [[ -z "$ZELLIJ_DISABLED" ]] && [[ -t 0 ]] && [[ -t 1 ]] && [[ -t 2 ]]; then
        if [[ "$ZELLIJ_AUTO_ATTACH" == "true" ]]; then
            zellij attach -c
        else
            zellij
        fi

        if [[ "$ZELLIJ_AUTO_EXIT" == "true" ]]; then
            exit
        fi
fi
oleynikandrey commented 1 month ago

With this condition env -i HOME="$HOME" /bin/zsh -i -l -c 'cd ~/; /usr/bin/env' still runs zellij, but I see not errors inZed logs.

mrnugget commented 1 month ago

With this condition env -i HOME="$HOME" /bin/zsh -i -l -c 'cd ~/; /usr/bin/env' still runs zellij, but I see not errors inZed logs.

Yeah, but that has a terminal attached to it :) What I meant was that you could modify the script and then try it in Zed again. Because in Zed, there is no TTY attached to stdin/stdout/stderr, so zellij shouldn't be started.