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

Can't launch neovide --wsl: ERROR: Unexpected output from neovim binary #2049

Closed
thallada opened this issue Sep 24, 2023 · 21 comments
Closed
Labels
bug Something isn't working

Comments

@thallada
Copy link

Describe the bug
I have neovide installed on windows and neovim installed inside WSL (with brew install neovim).

Inside a WSL shell I can successfully launch nvim and this is the output of nvim -v:

nvim -v
NVIM v0.9.2
Build type: Release
LuaJIT 2.1.0-beta3

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "
/home/linuxbrew/.linuxbrew/Cellar/neovim/0.9.2/share/nvim"

Run :checkhealth for more info

I think this PR started to cause the bug for me: #1946

To Reproduce
Steps to reproduce the behavior:

  1. Launch neovide with --wsl option: "C:\Program Files\Neovide\neovide.exe" --wsl
  2. Does not launch and displays error:
ERROR: Unexpected output from neovim binary:
/home/linuxbrew/.linuxbrew/bin/nvim -v
Check that your shell doesn't output anything extra when running:
wsl '$SHELL' -lc '/home/linuxbrew/.linuxbrew/bin/nvim -v'
"C:\Program Files\Neovide\neovide.exe" --wsl

I ran wsl '$SHELL' -lc '/home/linuxbrew/.linuxbrew/bin/nvim -v' in a cmd.exe shell and I get the error:

fish: Unknown command: '$SHELL'
fish:
'$SHELL' -lc '/home/linuxbrew/.linuxbrew/bin/nvim -v'
^

I think this has something to do with having my WSL shell set to the fish shell? I tried setting the $SHELL environment inside WSL to /usr/bin/fish so that echo $SHELL returns /usr/bin/fish, but I still get the same error.

Also if I run wsl 'fish' -lc '/home/linuxbrew/.linuxbrew/bin/nvim -v or wsl 'bash' -lc '/home/linuxbrew/.linuxbrew/bin/nvim -v I get the version printed correctly:

NVIM v0.9.2
Build type: Release
LuaJIT 2.1.0-beta3                                                                                                                                                                                                                                     system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "
/home/linuxbrew/.linuxbrew/Cellar/neovim/0.9.2/share/nvim"

Run :checkhealth for more info

So it is not understanding the $SHELL variable despite having set that in both .bashrc and .config/fish/config.fish.

Expected behavior
I can launch neovide in wsl.

Desktop (please complete the following information):

  • OS: Windows 10 Pro (10.0.19044 Built 19044)
  • Neovide Version 0.11.2
  • Neovim Version 0.9.2

Please run neovide --log and paste the contents of the .log file created in the current directory here:

I can't because I can't launch neovide

@thallada thallada added the bug Something isn't working label Sep 24, 2023
@thallada
Copy link
Author

I rolled back to Neovide 0.11.1 and I can launch neovide.exe --wsl now. So this is only an issue in Neovide 0.11.2.

@fredizzimo
Copy link
Member

Coincidentally, we debugged a very similar issue in the discord channel an hour ago.

wsl '$SHELL' -lc '/home/linuxbrew/.linuxbrew/bin/nvim -v' does not work from cmd, but it should in powershell. It will however not very likely give you any useful information other than what you already got.

If you change

let error_message_prefix = format!(
concat!(
"ERROR: Unexpected output from neovim binary:\n",
"\t{bin} -v\n",
"Check that your shell doesn't output anything extra when running:",
"\n\t"
),
bin = bin
);

to

                let error_message_prefix = format!(
                    concat!(
                        "ERROR: Unexpected output from neovim binary:\n",
                        "\t{bin} -v\n",
                        "stdout: {stdout}\n",
                        "stderr: {stderr}\n",
                        "Check that your shell doesn't output anything extra when running:",
                        "\n\t"
                    ),
                    bin = bin,
                    stdout = stdout,
                    stderr = String::from_utf8_lossy(&output.stderr),
                );

It will give you more information, and likely you will see the following stderr

your 131072x1 screen size is bogus. expect trouble

This output comes from here https://gitlab.com/procps-ng/procps/-/blob/bfb0eadc38e789737dec7f14dd7a7ac00f5f0761/src/ps/global.c#L287

Most likely there's something in your init files that calls ps, which gives this error. I think you can work around it by defining the environment variables COLUMNS and LINES to something reasonable.

But the real fix is to somehow figure out how to launch wsl so that it creates a properly sized terminal. We might have to create a pseudoterminal ourselves and use that for launching the wsl commands. Or alternatively force those environment variables form within neovide.

This is also a very commonly reported problem in Visual Studio Code, and there they just ignore that specific error. But I don't like that solution.

@fredizzimo
Copy link
Member

And we should also change the output to report something like that by default.

@thallada
Copy link
Author

thallada commented Oct 6, 2023

I tried setting the COLUMNS and LINES env variables in .bashrc, .config/fish/config.fish but that didn't change anything.

Unfortunately, I'm having trouble compiling this repo as well so I can't make that change to see what the real error is.

I can report that wsl '$SHELL' -lc '/home/linuxbrew/.linuxbrew/bin/nvim -v' does indeed run in Powershell but errors in cmd.exe.

@fredizzimo
Copy link
Member

For bash you need to set them in .profile or .bash_profile, since .bashrc is not source by Neovide. It's only sourced in for interactive shells, and Neovide use no-interactive login shells, so that output from screenfetch for example doesn't mess with the Neovim communication.

I don't use fish shell myself, but as far as I understand config.fish should be sourced in both interactive and non-interactive shells and you can use status --is-interactive to check. So setting the environment variables there should work.

On zsh the correct place is .zshenv or .zshprofile.

And for me, the following worked when I tested as long as it's in the correct place.

export COLUMNS=80
export LINES=30

The root cause is the ps command, you have something in your init scripts that calls ps, so another solution is to find that, and either remove it or ensure that both the stdout and stderr are either read or redirected to /dev/null

@Kethku
Copy link
Member

Kethku commented Nov 8, 2023

Closing as this looks addressed. Feel free to reopen if there are still issues

@Kethku Kethku closed this as completed Nov 8, 2023
@fredizzimo
Copy link
Member

I'm re-opening this. We do have a better error message now, but the root cause is still there and we have hade a few different reports. For example no-one has been able to track down exactly what triggers the ps command in the configuration. So that we can instruct people to just fix that.

Also, while manually exporting COLUMNS and LINES fixes the problem, it's not really a valid workaround since it can break other things. A slightly better workaround would be to do it inside Neovide just for the shells started by it. Or somehow trick ps to think that a terminal is attached. But I don't want to put that workaround in before we have found the root cause, because it could be better to just fix that.

@fredizzimo fredizzimo reopened this Nov 8, 2023
@liamwh
Copy link

liamwh commented Nov 13, 2023

This issue is definitely not solved. I am getting this issue with both pwsh and cmd using neovide 0.11.2:

Microsoft Windows [Version 10.0.22621.2428]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Liam>neovide --wsl

C:\Users\Liam>ERROR: Unexpected output from neovim binary:
        /home/linuxbrew/.linuxbrew/bin/nvim -v
Check that your shell doesn't output anything extra when running:
        wsl '$SHELL' -lc '/home/linuxbrew/.linuxbrew/bin/nvim -v'

Output of the command:

NVIM v0.9.2
Build type: Release
LuaJIT 2.1.0-beta3

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "
/home/linuxbrew/.linuxbrew/Cellar/neovim/0.9.2/share/nvim"

Run :checkhealth for more info

I am using zsh 5.8.1 with Oh My Zsh.

❯ zsh --version
zsh 5.8.1 (x86_64-ubuntu-linux-gnu)

@fredizzimo
Copy link
Member

@liamwh, can you run with the latest master version, it should show more info, it should show both the stdout and stderr here:

"ERROR: Unexpected output from neovim binary:\n",
"\t{bin} -v\n",
"stdout: {stdout}\n",
"stderr: {stderr}\n",
"Check that your shell doesn't output anything extra when running:",
"\n\t"

@thallada
Copy link
Author

I just tried running the latest main version and got this error:
neovide

So the stderr bit there must be the problem? I don't get that stderr output if I just run nvim -v inside a wsl shell. I also don't get that output if I run wsl '$SHELL' -lc '/home/linuxbrew/.linuxbrew/bin/nvim -v' from powershell.

@Parsifa1
Copy link

i have the same problem
image

@rachartier
Copy link

rachartier commented Jan 10, 2024

Hello,

I had the same problem under WSL2 with Ubuntu 22.04 and zsh.
The problem was due to "ssh-agent" which was launched automatically each time the shell was launched.

My .zprofile :

$ cat ~/.zprofile
if [ -z "$SSH_AUTH_SOCK" ]; then
   # Check for a currently running instance of the agent
   RUNNING_AGENT="`ps -ax | grep 'ssh-agent -s' | grep -v grep | wc -l | tr -d '[:space:]'`"
   if [ "$RUNNING_AGENT" = "0" ]; then
        # Launch a new instance of the agent
        ssh-agent -s &> $HOME/.ssh/ssh-agent
   fi
   eval `cat $HOME/.ssh/ssh-agent`
fi

To solve this, I had to delete ~/.zprofile
Check your bashrc, zshrc, or others for a line that launches ssh-agent

You can also redirect the output to /dev/null

Now it works it seems.

@fredizzimo
Copy link
Member

I think we should just automatically define these two environment variables when launching Neovim, since wsl.exe does not seem to set any terminal size when running as a hidden window

export COLUMNS=80
export LINES=30

#2049 (comment)

@Paliago
Copy link

Paliago commented Feb 2, 2024

Hello,

I had the same problem under WSL2 with Ubuntu 22.04 and zsh. The problem was due to "ssh-agent" which was launched automatically each time the shell was launched.

My .zprofile :

$ cat ~/.zprofile
if [ -z "$SSH_AUTH_SOCK" ]; then
   # Check for a currently running instance of the agent
   RUNNING_AGENT="`ps -ax | grep 'ssh-agent -s' | grep -v grep | wc -l | tr -d '[:space:]'`"
   if [ "$RUNNING_AGENT" = "0" ]; then
        # Launch a new instance of the agent
        ssh-agent -s &> $HOME/.ssh/ssh-agent
   fi
   eval `cat $HOME/.ssh/ssh-agent`
fi

To solve this, I had to delete ~/.zprofile Check your bashrc, zshrc, or others for a line that launches ssh-agent

You can also redirect the output to /dev/null

Now it works it seems.

Removing my .zprofile worked for me as well although the content was vastly different.

@fredizzimo
Copy link
Member

I will check if we can make COLUMNS and LINES be defined automatically when launching WSL from neovide. That should fix the issue.

This at the top of .zshenv or .zshprofile should fix the issue

export COLUMNS=80
export LINES=30

At least it did for me when I tested it earlier.

But it's not a good general workaround, since we don't want to set it when running wsl in a terminal the normal way. It should only be set when Neovide launches wsl.

@DZappala
Copy link
Contributor

DZappala commented Feb 21, 2024

The above fix, export COLUMNS=80 and export LINES=30 doesn't seem to work for me. The error is as follows:

TRACE [neovide] Neovide version: 0.12.2
DEBUG [neovide::settings::window_size] Loaded window settings: 
  Windowed { position: PhysicalPosition { x: 71, y: 199 }, 
  pixel_size: Some(PhysicalSize { width: 1454, height: 763 }), 
  grid_size: Some(Dimensions { width: 132, height: 34 }) }

ERROR [neovide::error_handling] Neovide just crashed :(
This is the error that caused the crash. In case you don't know what to do with this,
   please feel free to report this on https://github.com/neovide/neovide/issues!

ERROR: Unexpected output from neovim binary:
        /home/[username]/.local/bin/lvim -v
stdout: NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1703358377

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "
/home/linuxbrew/.linuxbrew/Cellar/neovim/0.9.5/share/nvim"

Run :checkhealth for more info

stderr: your 80x1 screen size is bogus. expect trouble
your 80x1 screen size is bogus. expect trouble

Check that your shell doesn't output anything extra when running:
        wsl '$SHELL' -lc '/home/[username]/.local/bin/lvim -v'

The above error shows I'm pointing to vim via lunarvim, but I attempted this with vanilla nvim as well.

You'll also note, my COLUMNS env var is being assigned correctly, but LINES is not (eg. 80x1). This holds true whether I define them in .profile or .bashrc, in fact setting them in .profile seemingly does nothing.

@fredizzimo
Copy link
Member

The bug was reported to Microsoft in November, but I don't have high hopes for a fix soon.

So, I guess the best option left is to ignore the offending line, and hope for the best then. All the other stderr output should still be checked, and only lines matching your \d+x\d+ screen size is bogus. expect trouble should be ignored.

Intellij made a tool to fix it, but I don't think we need to go there JetBrains/intellij-community@44be55a

I'm currently on Linux, and it might take a few days until I'm back on Windows to fix this. But it should be an easy fix if someone wants to do it.

@DZappala
Copy link
Contributor

DZappala commented Feb 21, 2024

I'm currently on Linux, and it might take a few days until I'm back on Windows to fix this. But it should be an easy fix if someone wants to do it.

I don't have perms to make a new branch for a PR, but here's a fix.

// command.rs 
fn neovim_ok (...)
...
if !(stdout.starts_with("NVIM v") && output.stderr.is_empty()) {
  let win_wsl_screen_size_error =
    Regex::new(r"your \d+x\d+ screen size is bogus. expect trouble").unwrap();
  let stderr = String::from_utf8_lossy(&output.stderr);
  if win_wsl_screen_size_error.is_match(&stderr) {
    return Ok(true);
  }

  let error_message_prefix = format!(
  concat!(
      "ERROR: Unexpected output from neovim binary:\n",
      "\t{bin} -v\n",
      "stdout: {stdout}\n",
      "stderr: {err}\n",
      "Check that your shell doesn't output anything extra when running:",
      "\n\t"
    ),
    bin = bin,
    stdout = stdout,
    err = stderr,
  );

  if is_wsl {
    bail!("{error_message_prefix}wsl '$SHELL' -lc '{bin} -v'");
  } else {
    bail!("{error_message_prefix}$SHELL -lc '{bin} -v'");
  }
}
...
  • added Regex cargo (not needed if there was already a way to create regex strings)
  • added early out of if statement if regexp is matched
    • I had wanted to add this to the if check itself but callingString::from_utf8_lossy() seems to consume the stderr and we need that for later in the fn.

@fredizzimo
Copy link
Member

@DZappala, thank you.

You should have permissions to make a PR, everyone does. But you need to do it from your own fork.

But one thing, I think you need to do the check for all lines separately, otherwise there might be other standard error output.

DZappala added a commit to DZappala/neovide that referenced this issue Feb 21, 2024
@DZappala
Copy link
Contributor

You should have permissions to make a PR, everyone does. But you need to do it from your own fork.

Good to go! #2374

But one thing, I think you need to do the check for all lines separately, otherwise there might be other standard error output.

Thanks, loops through lines now rather than checking the entire stderr so we don't ignore other errors.

fredizzimo pushed a commit that referenced this issue Feb 21, 2024
* Can't launch neovide --wsl: ERROR: Unexpected output from neovim binary #2049

ignored error for wsl window size

* fix: loop lines of stderr checking for regexp

* updated logic to print lines at indices following a caught wsl error

* revert variable name to original
@fredizzimo
Copy link
Member

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

No branches or pull requests

8 participants