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

Preview in browser fails in WSL with: exec: "xdg-open": executable file not found in $PATH #826

Closed
valorin opened this issue Apr 24, 2020 · 10 comments · Fixed by #1708
Closed
Labels
bug Something isn't working

Comments

@valorin
Copy link

valorin commented Apr 24, 2020

Describe the bug

The Preview in Browser option for a new pull request (via gh pr create) fails with the following error when used in WSL (I'm using the Pengwin distro on WSL2):

exec: "xdg-open": executable file not found in $PATH

As a result, you lose the PR body you've typed into the editor and have to start the PR creation process again.

$ gh --version
gh version 0.7.0 (2020-04-22)
https://github.com/cli/cli/releases/tag/v0.7.0

$ wslsys
Locale: en_AU
Release Install Date: Sat Apr 18 18:02:48 AEST 2020
Branch: rs_prerelease
Build: 19608
Full Build: 19608.1000.amd64fre.rs_prerelease.200410-1438
Display Scaling: 1
Windows Theme: light
Windows Uptime: 0d 13h 55m
WSL Uptime: 0d 5h 16m
WSL Release: Pengwin
WSL Kernel: Linux 4.19.104-microsoft-standard
Packages Count: 659

Steps to reproduce the behavior

  1. Using WSL on Windows 10
  2. Follow the prompts in gh pr create
  3. Select the Preview in Browser option

Expected vs actual behavior

This error is thrown and the command exits, losing all information:

exec: "xdg-open": executable file not found in $PATH

Ideally it should open the browser on the host to preview the PR, as if it was run on the host directly. wslview is included with most WSL distros and can be used to open the browser in Windows 10. More information: https://github.com/wslutilities/wslu

The alternative would be to provide the user the option to submit the PR directly or display a URL to manually paste into the browser for the preview.

Logs

valorin@Pengwin:~/dev/project/www (FB834)$ gh pr create

Creating pull request for FB834 into master in project/project-www

? Title FB834: Tweak width of invoice to/from/status for comfort
? Body <Received>
? What's next? Preview in browser
Enumerating objects: 13, done.
Counting objects: 100% (13/13), done.
Delta compression using up to 4 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 1.43 KiB | 1.43 MiB/s, done.
Total 7 (delta 6), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (6/6), completed with 6 local objects.
remote:
remote: Create a pull request for 'FB834' on GitHub by visiting:
remote:      https://github.com/project/project-www/pull/new/FB834
remote:
To github.com:project/project-www.git
 * [new branch]        HEAD -> FB834
Branch 'FB834' set up to track remote branch 'FB834' from 'origin'.
Opening github.com/project/project-www/compare/master...FB834 in your browser.
exec: "xdg-open": executable file not found in $PATH
@valorin valorin added the bug Something isn't working label Apr 24, 2020
@mislav
Copy link
Contributor

mislav commented May 7, 2020

As a result, you lose the PR body you've typed into the editor and have to start the PR creation process again.

Ouch, sorry for that. We should try to save your PR title & body on failure so you can reuse those on next retry.

wslview is included with most WSL distros and can be used to open the browser in Windows 10

Thanks for sharing that! We will try to detect and use that in the future. Until then, you can set export BROWSER=wslview in the shell where you use gh and GitHub CLI will use that executable when opening a browser.

@valorin
Copy link
Author

valorin commented May 7, 2020

Awesome, thanks! I'll enable export BROWSER=wslview now. 😁

@viperfx
Copy link

viperfx commented May 9, 2020

For me, it opens at http://127.0.0.1:39337/callback?browser_session_id=.... and chrome cannot connect to this server.

EDIT:

Followed comment in #597 and its working now!

@jetersen
Copy link

jetersen commented Jun 12, 2020

This is my tiny hack for xdg-open not being available and without need to install xdg-utils other tools might stumble ie. kubelogin

use these two tweaks for the best experience on WSL.

export BROWSER=wslview
sudo ln -s $(which wslview) /usr/local/bin/xdg-open

@mislav
Copy link
Contributor

mislav commented Jun 12, 2020

@jetersen Thanks, but this seems like more steps than just setting export BROWSER=wslview in your shell config file 🤔 Do you recommend people to take yours over the environment variable approach?

@jetersen
Copy link

jetersen commented Jun 12, 2020

No I suggest both fixes to have the most success with compatibility.

I still use export BROWSER=wslview for those programs that support it.
Sadly kubelogin uses pkg/browser which seems unmaintained: https://github.com/pkg/browser/pulse/monthly
PRs are there that would fix compatiblity.

I put my BROWSER=wslview into the /etc/environment when multiple users are involved on WSL.

@mislav
Copy link
Contributor

mislav commented Jun 17, 2020

No I suggest both fixes to have the most success with compatibility.

@jetersen Ah I see now that you were not solving this issue just for gh, but for other tools as well. Thanks!

@felipecrs
Copy link

felipecrs commented Jun 19, 2020

I take a similar approach as @jetersen, but easier:

sudo ln -s $(which wslview) /usr/local/bin/xdg-open

Just run and you should be good to go.

@jetersen
Copy link

jetersen commented Jun 19, 2020

@felipecassiors good point, I did not think of symlinking.
I suspect search engines are leading a lot of users to this issue.

@Stilborg
Copy link

Stilborg commented Feb 8, 2021

This is my tiny hack for xdg-open not being available and without need to install xdg-utils other tools might stumble ie. kubelogin

use these two tweaks for the best experience on WSL.

export BROWSER=wslview
sudo ln -s $(which wslview) /usr/local/bin/xdg-open

Thx @jetersen you saved me! , fandme verdensklasse

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

Successfully merging a pull request may close this issue.

6 participants