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
50.72k stars 3.14k forks source link

Opening a project with zed cli has go list: initialization failed error #13888

Open amir20 opened 4 months ago

amir20 commented 4 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

I have been using Zed for a few days. So far I love it. I mostly use Go, Vue and Tailwind. It works with all of these out of the box. However, when opening one of my projects, with zed . I see an error:

go list: initialization failed: packages.Load error: err: exit status 1: stderr: failed to initialize build cache at /Users/amirraminfar

Going to go.mod I see:

Screenshot 2024-07-05 at 7 47 18 PM

However, if I close Zed and open it using the regular launcher then it all works.

I have tried:

When I open a different project, it seems to work just fine with zed cli. I am not sure what is different about Dozzle

Steps to produce:

Opening same project with Mac Launcher works just fine.

Environment

Zed: v0.142.6 (Zed) OS: macOS 14.5.0 Memory: 16 GiB Architecture: aarch64

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

Screenshot 2024-07-05 at 7 47 18 PM Screenshot 2024-07-05 at 7 50 36 PM

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

Zed.log

amir20 commented 4 months ago

After a delay, I see similar logs:

2024-07-06T14:36:51-07:00 [WARN] Generic lsp request to gopls failed: can't find definitions for file type go.mod
2024-07-06T14:36:51-07:00 [WARN] Generic lsp request to gopls failed: err: exit status 1: stderr: failed to initialize build cache at /Users/amirraminfar
/Library/Caches/go-build: mkdir /Users/amirraminfar
: permission denied

2024-07-06T14:36:51-07:00 [ERROR] crates/project/src/project.rs:7519: err: exit status 1: stderr: failed to initialize build cache at /Users/amirraminfar
/Library/Caches/go-build: mkdir /Users/amirraminfar
: permission denied

Notices the line breaks after Users/amirraminfar. I think the bug is that for some reason Zed is trying to create a directory at /Users/amirraminfar

notpeter commented 4 months ago

Looking at the Golang source code, that error is being triggered here:

And dir in that context is build by DefaultDir at src/cmd/go/internal/cache/default.go#L79

Which calls the UserCacheDir for darwin at src/os/file.go#L487-L492.

Is it possible that your HOME environment variable is not set correctly and contains a trailing newline? Or perhaps GOCACHE is set with a newline in the middle?

Edit: I think you might have a unicode whitespace character, [?2004l is Unicode Character “ ” (U+2004) Three-Per-Em Space Unicode Character. So it might be possible you have a pasted a whitespace character somewhere.

amir20 commented 4 months ago
❯ echo $HOME                                                                                                                                                                           7:49:42
/Users/amirraminfar

❯ echo $GOCACHE                                                                                                                                                                        

Gocache seems to be empty.

So it might be possible you have a pasted a whitespace character somewhere

I noticed that too. But I found that from the logs. In my code, I can't find anything that might be a unicode char.

I am happy to debug if needed. But I also set Zed up in my new laptop from work and it resulted in the same error. So something is consistent.

I do think its something in my project. You should be able to reproduce it with

git clone https://github.com/amir20/dozzle.git
cd dozzle 
zed .
amir20 commented 4 months ago

I have a very simple project that this happens:

main.go

package main

import (
    "fmt"
)

func main() {
    fmt.Println("Hello, World!")
}

go.mod

module github.com/amir20/test

go 1.19

zed . will have the permission denied error.

notpeter commented 4 months ago

I have a very simple project that this happens:

I cannot reproduce the issues you are having. I think this must be something specific to your environment. When I create this simple project and open it with zed . it works as expected.

Can you see if you can reproduce with Zed on another computer?

amir20 commented 4 months ago

It happened on my work laptop and another laptop. But both of those laptops were very similar in configuration and installed Go with brew.

Something definitely doesn't feel right but I am not sure how to go about debugging it.

I can try setting up a new env later next week, but it might be hard because I can't just use a VM to test.

AngerM commented 4 months ago

I've run into the same. I wonder if theres something going on w/ vscode, neovim and zed all using gopls on the same projects. Potentially one of them is running gopls as a different user?

amir20 commented 4 months ago

Personally, I didn't have other IDEs open. I am still at loss to what might be causing this with zed . and not opening with GUI.

wfarr commented 3 months ago

I just came across this issue and I noticed a couple items:

This is happening on macOS 14.6.1, with stock bash/zsh and fish from homebrew.

I'm assuming this is why launching from outside zed . was working for you as well (not launching via the fish shell). This suggests that something may be funky with the environment loading from fish vs other shells.

amir20 commented 3 months ago

Great find @wfarr. I would have not guessed fish is the culprit.

ananthb commented 3 months ago

Damn, I use fish and I'm having the same error.

johndeng commented 3 months ago

I got the same issue with fish shell.

johndeng commented 3 months ago

I resolved the issue by setting the GOCACHE environment variable to the $HOME directory.

# ~/.config/fish/config.fish
set -x GOCACHE $HOME/.cache/go-cache
amir20 commented 3 months ago

Hmmm I did set -x GOCACHE $HOME/.cache/go-cache and then zed . and I still see the same error.

❯ env | grep GO                                                                                                                                9:08:05
GOCACHE=/Users/araminfar/.cache/go-cache

Not sure why it is not working.

hovsater commented 3 months ago

What's the permissions on the /Library/Caches/go-build folder?

amir20 commented 3 months ago

So correction:

set -x GOCACHE $HOME/.cache/go-cache does fix it on a few projects for me.

However, on my main project I still see go list: packages.Load error: err: exit status 1: stderr: go: could not create module cache: mkdir /Users/araminfar [?2004l: permission denied

@hovsater I assume you mean permissions for $HOME/.cache/go-cache. Which is:

drwxr-xr-x araminfar staff 8.1 KB Thu Aug 22 09:07:44 2024 --  go-cache

I haven't had a chance to go deep in all the env vars. But knowing this is Fish related helps.

amir20 commented 2 months ago

Maybe something has changed, but this seems to be working now in version Zed 0.153.6

notpeter commented 2 months ago

I wonder whether it was:

Which was released as part of 0.153.x.

Has anyone else seen this since updating to 0.153.x (current Zed Stable as of 2024-09-23)?

xiy commented 1 month ago

I saw this on both 0.153.6 and now on 0.155.2, a few env details:

MacOS 10.15 Sequoia Fish 3.7.0 (via brew) Go 1.23.1 (via brew)

After upgrading Fish to 3.7.1 it seems to have stopped, so its worth a try as this seems to be Fish-related 🐟

diwakergupta commented 1 month ago

FYI I still see this with Zed 0.157.4, OS X, go 1.23.2. I do use fish shell, but I'm launching Zed directly from Finder / Spotlight. The only permission denied related thing in the logs is:

2024-10-16T14:16:00.763401-04:00 [WARN] request completed with error: failed to connect to the server
2024-10-16T14:16:00.800587-04:00 [ERROR] failed to fetch cached embeddings via cloud model

Caused by:
    RPC request GetCachedEmbeddings failed: permission denied

I also see some gopls errors:

2024-10-16T14:16:03.167193-04:00 [WARN] Generic lsp request to gopls failed: no package metadata for file file:///...
2024-10-16T14:16:03.167413-04:00 [ERROR] no package metadata for file file:...

Does anyone have a reliable workaround? I'll try setting GOCACHE, but I don't see any references to GOCACHE in the logs so I'm not sure how or why that should help.

arugal commented 1 month ago

https://zed.dev/docs/languages/go#setup

For me, go install golang.org/x/tools/gopls@latest solved the problem

Too early to rejoice, today is the same problem

juev commented 2 days ago

I also have a problem playing on Zed 0.162.5 and fish shell.