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

PATH issues with Fish shell on macOS #21655

Closed
NinoFloris opened this issue Mar 1, 2017 · 77 comments
Closed

PATH issues with Fish shell on macOS #21655

NinoFloris opened this issue Mar 1, 2017 · 77 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug install-update VS Code installation and upgrade system issues macos Issues with VS Code on MAC/OS X
Milestone

Comments

@NinoFloris
Copy link

NinoFloris commented Mar 1, 2017

So while having a problem PATH related I created an issue in the omnisharp vscode repo about this. However right after doing a quick chsh /bin/bash and a restart of vscode my suspicions were right and now I'm coming back to you guys.

The issue in omnisharp vscode:
dotnet/vscode-csharp#1259

Previous fix I'm pointing to:
#8434

Seems that somehow this fix regressed again. Or my shell does even more effort to break it...

I'm still using fish with powerline as my shell and it seems to break the env (and in turn PATH) parsing again.

I propose a change to the PATH resolution strategy for OSX:

  • Run path_helper for an initial view of an ok customizable PATH of an OSX installation. It gathers all paths from the file /etc/paths and paths in files in /etc/paths.d like the one for dotnet. It outputs a PATH string of these paths.
  • Do the hacky thing with reading out a login shell's env and parsing the PATH from it.
  • Use the hacky output if there is actually any. Every login shell runs path_helper but also includes all user customizations to PATH from say .bash_profile.
  • If the shell is so custom it breaks the hacky way of fishing out the PATH then just use the path_helper output.

This way the result will at least always be a working env (for say quite integrated things like spawning a dotnet process for doing a restore).
Because everyone should be able to expect that after installing a pkg like the dotnet cli vscode (and its extensions) can always find and work with it seamlessly.

dotnet --info output:
.NET Command Line Tools (1.0.0-rc4-004849)

Product Information:
Version: 1.0.0-rc4-004849
Commit SHA-1 hash: 7dcefb5076

Runtime Environment:
OS Name: Mac OS X
OS Version: 10.12
OS Platform: Darwin
RID: osx.10.12-x64
Base Path: /usr/local/share/dotnet/sdk/1.0.0-rc4-004849
VS Code version: 1.10.0-insider
C# Extension version: 1.7.0
@gregg-miskelly
Copy link
Member

@weinand @joaomoreno would I be correct in assuming that if VS Code fixes this issue, the extra environment settings will automatically propagate to the C# extension processes?

@joaomoreno
Copy link
Member

joaomoreno commented Mar 2, 2017

Did this really regress for you? Was it working before? In which version did it stop working?

cc @jrieken

@joaomoreno joaomoreno added the info-needed Issue requires more information from poster label Mar 2, 2017
@NinoFloris
Copy link
Author

NinoFloris commented Mar 2, 2017

@gregg-miskelly Yes as vscode is the host process from where you spawn new dotnet processes a shell like PATH will then allow it to actually find dotnet. Also each child process gets the env of the parent. That's why starting vscode from a terminal succeeds as a work-around.

@joaomoreno I picked up a new macbook a little while ago, copied over all my old dotfiles for fish etc and installed vscode. To my knowledge it didn't work since I got this new macbook.

A lot of extensions expect PATH to be filled like a shell so once this is fixed things will start working again. Whether such widespread expecatations are a good or bad thing is something I leave up to you.

@joaomoreno
Copy link
Member

joaomoreno commented Mar 2, 2017

OK, is PATH the only variable that is wrong, or are there other variables missing from Code's window?

You can figure this out by running F1, Developer Tools and then in the Console run process.env.

What version do you currently have, btw?

@NinoFloris
Copy link
Author

Everything in the env seems incorrect, no OMF keys, default path and missing all other customizations.

Tested with insiders latest and normal 1.10.1

@jrieken
Copy link
Member

jrieken commented Mar 2, 2017

Can you also try this in the dev tools console and compare with the previous output: process.lazyEnv.then(v => console.log(v))

@joaomoreno
Copy link
Member

@NinoFloris
Copy link
Author

@jrieken, exactly the same. @joaomoreno sadly no

@jrieken
Copy link
Member

jrieken commented Mar 2, 2017

Is $SHELL actually pointing to the right shell that you are using? We do this which is running node such that it dumps the env from the default shell. So, if the shell-variable points to the correct shell I would assume that node gets the correct variables inherited and that we then use the right variables too

const command = `'${process.execPath}' -p '"${mark}" + JSON.stringify(process.env) + "${mark}"'`;
		const child = cp.spawn(process.env.SHELL, ['-ilc', command], {
			detached: true,
			stdio: ['ignore', 'pipe', process.stderr],
			env
		});

@joaomoreno
Copy link
Member

If 1.9 doesn't work correctly, this is not a regression.

If you open the Developer Tools and run this in the console, what comes back?

(() => {
const electron = require('electron').remote.process.execPath;
const cp = require('child_process');
const mark = 'MARK123';
const env = Object.assign({}, process.env, {
    ELECTRON_RUN_AS_NODE: '1',
    ELECTRON_NO_ATTACH_CONSOLE: '1'
});
const command = `'${electron}' -p '"${mark}" + JSON.stringify(process.env) + "${mark}"'`;
const result = cp.spawnSync(process.env.SHELL, ['-ilc', command], {
    detached: true,
    stdio: ['ignore', 'pipe', process.stderr],
    env,
    encoding: 'utf8'
});
console.log(result.stdout);
})();

@NinoFloris
Copy link
Author

@jrieken yes, just did a which fish and compared it with an echo of SHELL identical paths

@joaomoreno it returns undefined

@NinoFloris
Copy link
Author

NinoFloris commented Mar 2, 2017

running the command directly

fish -ilc "'/Applications/Visual Studio Code.app/Contents/MacOS/Electron' -p '"MARK123" + JSON.stringify(process.env) + "MARK123"'"

Opens a new file in vscode with no contents, so it seems there is no issue with the command persé but the output is still incorrect

Nvm running this on my old laptop gives the same results, don't really know what -p does ;)

@joaomoreno
Copy link
Member

@NinoFloris It returns undefined, but should print something else in the console after 1 second or so. Nothing gets printed?

Running it standalone, you need the right env:

ELECTRON_RUN_AS_NODE=1 ELECTRON_NO_ATTACH_CONSOLE=1 fish -ilc "'/Applications/Visual Studio Code.app/Contents/MacOS/Electron' -p '"MARK123" + JSON.stringify(process.env) + "MARK123"'"

@NinoFloris
Copy link
Author

Nope from within vscode it returns nothing.

running

env ELECTRON_RUN_AS_NODE=1; env ELECTRON_NO_ATTACH_CONSOLE=1; fish -ilc "'/Applications/Visual Studio Code.app/Contents/MacOS/Electron' -p '"MARK123" + JSON.stringify(process.env) + "MARK123"'"

returns the right things!

Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.TBtCF6pWmO/Render
COLORFGBG=15;0
HOME=/Users/nfloris
ITERM_PROFILE=Default
ITERM_SESSION_ID=w3t0p0:BAF42606-4339-4892-A1C5-40759BC537AE
LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8
LC_CTYPE=UTF-8
LOGNAME=nfloris
OMF_CONFIG=/Users/nfloris/.config/omf
OMF_PATH=/Users/nfloris/.local/share/omf
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.node/bin:~/.terraform:~/.composer/vendor/bin
PWD=/Users/nfloris
SHELL=/usr/local/bin/fish
SHLVL=1
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.TakpSw68bL/Listeners
TERM=xterm-256color
TERM_PROGRAM=iTerm.app
TERM_PROGRAM_VERSION=3.0.13
TERM_SESSION_ID=w3t0p0:BAF42606-4339-4892-A1C5-40759BC537AE
TMPDIR=/var/folders/8n/pxszz5w97ml_9t3my9y16jpr0000gp/T/
USER=nfloris
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
__CF_USER_TEXT_ENCODING=0x1F6:0x0:0x0
ELECTRON_RUN_AS_NODE=1
Apple_PubSub_Socket_Render=/private/tmp/com.apple.launchd.TBtCF6pWmO/Render
COLORFGBG=15;0
HOME=/Users/nfloris
ITERM_PROFILE=Default
ITERM_SESSION_ID=w3t0p0:BAF42606-4339-4892-A1C5-40759BC537AE
LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8
LC_CTYPE=UTF-8
LOGNAME=nfloris
OMF_CONFIG=/Users/nfloris/.config/omf
OMF_PATH=/Users/nfloris/.local/share/omf
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.node/bin:~/.terraform:~/.composer/vendor/bin
PWD=/Users/nfloris
SHELL=/usr/local/bin/fish
SHLVL=1
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.TakpSw68bL/Listeners
TERM=xterm-256color
TERM_PROGRAM=iTerm.app
TERM_PROGRAM_VERSION=3.0.13
TERM_SESSION_ID=w3t0p0:BAF42606-4339-4892-A1C5-40759BC537AE
TMPDIR=/var/folders/8n/pxszz5w97ml_9t3my9y16jpr0000gp/T/
USER=nfloris
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
__CF_USER_TEXT_ENCODING=0x1F6:0x0:0x0
ELECTRON_NO_ATTACH_CONSOLE=1

@SapiensAnatis
Copy link

SapiensAnatis commented Mar 3, 2017

I can't be much help but I can confirm that using zsh I experience this issue with cargo run.

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "cargo",
    "isShellCommand": true,
    "args": ["run"],
    "showOutput": "always",
    "isBuildCommand": true
}

This JSON produces the errror

Failed to launch external program cargo run.
spawn cargo ENOENT

Although chsh to /bin/bash didn't fix the issue for me after relogging.

@joaomoreno
Copy link
Member

@NinoFloris

(() => {
const electron = require('electron').remote.process.execPath;
const cp = require('child_process');
const mark = 'MARK123';
const env = Object.assign({}, process.env, {
    ELECTRON_RUN_AS_NODE: '1',
    ELECTRON_NO_ATTACH_CONSOLE: '1'
});
const command = `'${electron}' -p '"${mark}" + JSON.stringify(process.env) + "${mark}"'`;
console.log(command);
console.log(process.env.SHELL);
const result = cp.spawnSync(process.env.SHELL, ['-ilc', command], {
    detached: true,
    stdio: ['ignore', 'pipe', process.stderr],
    env,
    encoding: 'utf8'
});
console.log(result);
console.log(result.stdout);
})();

Added a few more console.log calls... let me know what comes out.

@sietseringers
Copy link

I use the fish shell and have the exact same problem. The above snippet seems to return correct output:
'/Applications/Visual Studio Code.app/Contents/MacOS/Electron' -p '"MARK123" + JSON.stringify(process.env) + "MARK123"'
/usr/local/bin/fish
(The console.log(result); line doesn't paste well)

MARK123{"ANDROID_HOME":"/Users/john/Library/Android/sdk","Apple_PubSub_Socket_Render":"/private/tmp/com.apple.launchd.pwMyJ2Vo9p/Render","CLICOLOR":"1","COLORFGBG":"15;0","DISPLAY":"/private/tmp/com.apple.launchd.O7WsAbsJjt/org.macosforge.xquartz:0","ELECTRON_NO_ATTACH_CONSOLE":"1","ELECTRON_RUN_AS_NODE":"1","GOOGLE_API_KEY":"AIzaSyAQfxPJiounkhOjODEO5ZieffeBv6yft2Q","GOPATH":"/Users/john/go","HOME":"/Users/john","HOMEBREW_NO_ANALYTICS":"1","ITERM_PROFILE":"Default","ITERM_SESSION_ID":"w0t0p0:DFD238F3-D951-4C33-AFBC-6F8095A42E87","JAVA_HOME":"/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home","LC_ALL":"en_US.UTF-8","LC_CTYPE":"en_US.UTF-8","LOGNAME":"john","LSCOLORS":"GxFxCxDxBxegedabagaced","OMF_CONFIG":"/Users/john/.config/omf","OMF_PATH":"/Users/john/.local/share/omf","PATH":"/usr/local/sbin:/Users/john/bin:/Users/john/go/bin:/Users/john/.rvm/bin:/usr/local/sbin:/Users/john/bin:/Users/john/go/bin:/Users/john/.rvm/bin:/Users/john/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/MacGPG2/bin:/Library/TeX/texbin","PWD":"/Users/john","SHELL":"/usr/local/bin/fish","SHLVL":"4","SSH_AGENT_PID":"16312","SSH_AUTH_SOCK":"/private/tmp/com.apple.launchd.HrWUzNnMvL/Listeners","TERM":"xterm-256color","TERM_PROGRAM":"iTerm.app","TERM_PROGRAM_VERSION":"3.0.13","TERM_SESSION_ID":"w0t0p0:DFD238F3-D951-4C33-AFBC-6F8095A42E87","TMPDIR":"/var/folders/lv/5rvd6xqx20d8h0pych18kz8r0000gn/T/","USER":"john","VSCODE_CLI":"1","VSCODE_IPC_HOOK":"/Users/john/Library/Application Support/Code/1.10.1-main.sock","VSCODE_NLS_CONFIG":"{\"locale\":\"en-gb\",\"availableLanguages\":{}}","VSCODE_NODE_CACHED_DATA_DIR_30754":"/Users/john/Library/Application Support/Code/CachedData","VSCODE_PID":"30754","VSCODE_SHARED_IPC_HOOK":"/Users/john/Library/Application Support/Code/1.10.1-shared.sock","XPC_FLAGS":"0x0","XPC_SERVICE_NAME":"0","__CF_USER_TEXT_ENCODING":"0x1F5:0x0:0x0"}MARK123

In particular, process.env.PATH is correctly populated. The only thing I can think of that could be a problem is that in fish, the $PATH parts are separated differently:

> echo $PATH                                                                                                                                                       
/usr/local/sbin /Users/john/bin /Users/john/go/bin /Users/john/.rvm/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin /opt/X11/bin /usr/local/MacGPG2/bin /Library/TeX/texbin

@NinoFloris
Copy link
Author

NinoFloris commented Mar 6, 2017

Ok took some time to diagnose the issue myself, fish goes belly up when -i (interactive) in -ilc is used while no stdin is connected.

If I just pipe through stderr to inspect it in the process object this is the error shown

"stty: stdin isn't a terminal"

So the fix is easy, change

    stdio: ['ignore', 'pipe', process.stderr],

to

    stdio: ['pipe', 'pipe', process.stderr],

This also explains why I could get the command to work on the terminal as a stdin is surely connected in that case ^_^

@sietseringers
Copy link

That doesn't seem to work for me - but then, my problem seems to occur not when examining the shell environment (as I do have a correctly populated process.env.PATH), but only when launching executables such as sh.

@joaomoreno joaomoreno removed the info-needed Issue requires more information from poster label Mar 7, 2017
@joaomoreno joaomoreno added this to the March 2017 milestone Mar 7, 2017
@joaomoreno joaomoreno added the bug Issue identified by VS Code Team member as probable bug label Mar 7, 2017
@joaomoreno
Copy link
Member

Thanks for the fix @NinoFloris, will verify and push it.

@sietseringers I'm not entirely sure I understand your problem or whether it's an issue with Code itself. Can you create a separate issue and ping me in it?

@peabnuts123
Copy link

On OSX, VSCode 1.10.2, $PATH variable has started being /usr/bin:/bin:/usr/sbin:/sbinand now heaps of stuff doesn't work (like dotnet). Is this fix going to resolve this for me? Invoking VScode from terminal fixes the issue.

@cliffrowley
Copy link

Only running via code . works for me unfortunately - I have no idea why this would be.

@NinoFloris
Copy link
Author

NinoFloris commented Jun 16, 2017

@cliffrowley this is because each process inherits the environment (PATH variables and all) from their parent process.

As your shell can parse its own config without any issues it has a full environment it can pass down to any process it starts, like when you do code ., then internally vscode still fails to parse your terminal's config however it already inherited a parsed one from your shell and so all works even though it failed to do its own parsing.

The real problem here is that normally OSX processes are started by launchd (if you run via Finder, dock etc). launchd however doesn't parse your terminal config (it just doesn't know of it) and so does not pass down any of the necessary env variables. So vscode normally has to rely on its own env parsing mechanism and for more exotic shell configurations it breaks as it's basically a hack. That's why we're all here :)

@cliffrowley
Copy link

@NinoFloris thanks for the explanation - I was peripherally aware but without the specifics. Is this only a Fish shell issue?

@NinoFloris
Copy link
Author

It mostly is, but zsh also had some troubles as did some more exotic bash profiles, although I think all but Fish's problems have been hacked around by now

@cliffrowley
Copy link

@NinoFloris ah, brilliant - thanks for the pointers, I shall await a fix patiently and not worry about it affecting multi root support!

@joaomoreno
Copy link
Member

@NinoFloris I still can't reproduce this on my machine. I have Fish shell installed and set up as my default shell. And I can't reproduce the issue: I can easily get the environment I configured in ~/.config/fish/config.fish, on my machine. It will be easier if you simply get me the exact version number and let me know whatever customisations you have in Fish.

Nevertheless, I have created #29864 which additionally gets more info from path_helper. Let me know how it goes.

@joaomoreno
Copy link
Member

@NinoFloris Let me know when you try this out.

@joaomoreno joaomoreno modified the milestones: Backlog, July 2017 Jul 25, 2017
@wprater
Copy link
Contributor

wprater commented Aug 14, 2017

Im having issues with Fish and my PATH as well. It cannot find node nor shfmt when opening projects. In order to suppress these warnings, I must launch VS Code from the CLI.

@joaomoreno
Copy link
Member

cc @NinoFloris

@wprater
Copy link
Contributor

wprater commented Aug 31, 2017

hope I can help here, Ive been dealing with this for months on the Insiders builds. thanks!

@wprater
Copy link
Contributor

wprater commented Oct 13, 2017

for me, I feel this is related, since I've never been able to resolve this one without opening from CLI
#24961

@wprater
Copy link
Contributor

wprater commented Dec 6, 2017

this issue is no longer present for me in the latest insiders version!

@joaomoreno
Copy link
Member

Interesting. @NinoFloris you too?

@NinoFloris
Copy link
Author

I haven't had real issues for a while as tools are including more and more discovery logic to prevent these issues with relying on PATH :)

@joaomoreno
Copy link
Member

Alright man, I'll close this then. Sorry we didn't really address it.

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug install-update VS Code installation and upgrade system issues macos Issues with VS Code on MAC/OS X
Projects
None yet
Development

Successfully merging a pull request may close this issue.