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

gopls: packages.load error: JSON decoding failed : invalid character 'x' in string escape code #11647

Open
1 task done
xushuhui opened this issue May 10, 2024 · 29 comments
Open
1 task done
Labels
bug [core label] go Go programming language support language An umbrella label for all programming languages syntax behaviors

Comments

@xushuhui
Copy link

xushuhui commented May 10, 2024

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

I input command brew upgrade zed and zed version from 0.132.2 to 0.134.4.
this is error "gopls: packages.load error: JSON decoding failed : invalid character 'x' in string escape code " when I open exist go project in zed.

Environment

Zed: v0.134.4 (Zed)
OS: macOS 13.0.1
Memory: 16 GiB
Architecture: x86_64

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

image

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

2024-05-10T14:34:48+08:00 [ERROR] crates/gpui/src/elements/img.rs:344: Client(Error { kind: Timeout, context: None, source: Some(Error { description: "Timeout was reached", code: 28, extra: None }), source_type: Some("curl::error::Error"), local_addr: None, remote_addr: None })
2024-05-10T14:34:48+08:00 [ERROR] crates/gpui/src/elements/img.rs:344: Client(Error { kind: Timeout, context: None, source: Some(Error { description: "Timeout was reached", code: 28, extra: None }), source_type: Some("curl::error::Error"), local_addr: None, remote_addr: None })
2024-05-10T14:35:06+08:00 [ERROR] crates/gpui/src/elements/img.rs:344: Client(Error { kind: Timeout, context: None, source: Some(Error { description: "Timeout was reached", code: 28, extra: None }), source_type: Some("curl::error::Error"), local_addr: None, remote_addr: None })
2024-05-10T14:35:07+08:00 [WARN] Generic lsp request to gopls failed: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/suggest.go
2024-05-10T14:35:07+08:00 [ERROR] crates/project/src/project.rs:7009: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/suggest.go
2024-05-10T14:35:07+08:00 [ERROR] crates/gpui/src/elements/img.rs:344: Client(Error { kind: Timeout, context: None, source: Some(Error { description: "Timeout was reached", code: 28, extra: None }), source_type: Some("curl::error::Error"), local_addr: None, remote_addr: None })
2024-05-10T14:35:07+08:00 [ERROR] crates/gpui/src/elements/img.rs:344: Client(Error { kind: Timeout, context: None, source: Some(Error { description: "Timeout was reached", code: 28, extra: None }), source_type: Some("curl::error::Error"), local_addr: None, remote_addr: None })

@xushuhui xushuhui added admin read bug [core label] labels May 10, 2024
@Moshyfawn Moshyfawn added language An umbrella label for all programming languages syntax behaviors go Go programming language support diagnostics Feedback for diagnostics, error messages, logs, etc and removed triage diagnostics Feedback for diagnostics, error messages, logs, etc labels May 10, 2024
@xushuhui
Copy link
Author

xushuhui commented May 30, 2024

log file

2024-05-30T14:18:39+08:00 [ERROR] unexpected item event after pane was dropped
2024-05-30T14:19:08+08:00 [INFO] Initializing default prettier with plugins {}
2024-05-30T14:19:08+08:00 [INFO] starting language servers for Lua: lua-language-server
2024-05-30T16:40:01+08:00 [INFO] building git repository, `.git` path in the worktree: ".git"
2024-05-30T16:40:01+08:00 [INFO] Initializing default prettier with plugins {}
2024-05-30T16:40:01+08:00 [INFO] starting language servers for Go: gopls
2024-05-30T16:40:01+08:00 [INFO] starting language server "gopls", path: "/Users/xsh/fm/fm-suggest", id: 10
2024-05-30T16:40:01+08:00 [ERROR] crates/workspace/src/persistence/model.rs:313: No worktree for path: "/Users/xsh/.config/zed/settings.json"
2024-05-30T16:40:02+08:00 [INFO] found user-installed language server for Go. path: "/Users/xsh/go/bin/gopls", arguments: ["-mode=stdio"]
2024-05-30T16:40:02+08:00 [INFO] starting language server. binary path: "/Users/xsh/go/bin/gopls", working directory: "/Users/xsh/fm/fm-suggest", args: ["-mode=stdio"]
2024-05-30T16:40:02+08:00 [INFO] Language server with id 10 sent unhandled notification window/logMessage:
{
  "type": 1,
  "message": "2024/05/30 16:40:02 creating temp dir: mkdir /var/folders/d9/h1ryx87j3pq8gcx7knm2xssh0000gn/T/\n\u001b[?2004l/gopls-6762.1: no such file or directory\n"
}
2024-05-30T16:40:02+08:00 [WARN] Generic lsp request to gopls failed: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-05-30T16:40:02+08:00 [ERROR] crates/project/src/project.rs:7172: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-05-30T16:40:03+08:00 [WARN] Generic lsp request to gopls failed: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-05-30T16:40:03+08:00 [ERROR] crates/project/src/project.rs:7172: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-05-30T16:40:07+08:00 [INFO] Initializing default prettier with plugins {}
2024-05-30T16:40:07+08:00 [INFO] starting language servers for Go Mod: gopls
2024-05-30T16:42:15+08:00 [ERROR] crates/lsp/src/lsp.rs:779: oneshot canceled
2024-05-30T16:42:15+08:00 [INFO] building git repository, `.git` path in the worktree: ".git"
2024-05-30T16:42:15+08:00 [INFO] Initializing default prettier with plugins {}
2024-05-30T16:42:15+08:00 [INFO] starting language servers for Go: gopls
2024-05-30T16:42:15+08:00 [INFO] starting language server "gopls", path: "/Users/xsh/fm/fm-suggest", id: 11
2024-05-30T16:42:15+08:00 [ERROR] crates/workspace/src/persistence/model.rs:313: Deserializer does not exist for item kind: diagnostics
2024-05-30T16:42:16+08:00 [INFO] found user-installed language server for Go. path: "/Users/xsh/go/bin/gopls", arguments: ["-mode=stdio"]
2024-05-30T16:42:16+08:00 [INFO] starting language server. binary path: "/Users/xsh/go/bin/gopls", working directory: "/Users/xsh/fm/fm-suggest", args: ["-mode=stdio"]
2024-05-30T16:42:16+08:00 [INFO] Language server with id 11 sent unhandled notification window/logMessage:
{
  "type": 1,
  "message": "2024/05/30 16:42:16 creating temp dir: mkdir /var/folders/d9/h1ryx87j3pq8gcx7knm2xssh0000gn/T/\n\u001b[?2004l/gopls-6871.1: no such file or directory\n"
}
2024-05-30T16:42:16+08:00 [WARN] Generic lsp request to gopls failed: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-05-30T16:42:16+08:00 [ERROR] crates/project/src/project.rs:7172: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-05-30T16:42:21+08:00 [ERROR] crates/lsp/src/lsp.rs:779: oneshot canceled

@Etesam913
Copy link

I am having the same issue

@benjsto
Copy link

benjsto commented May 31, 2024

I also have run into this issue in recent weeks!

@d1y
Copy link
Contributor

d1y commented May 31, 2024

Can someone provide a minimum example repo?

@xushuhui
Copy link
Author

xushuhui commented Jun 3, 2024

I update zed 0.137.6 today, the problem no fixed, log file is

2024-06-03T10:09:18+08:00 [INFO] ========== starting zed ==========
2024-06-03T10:09:18+08:00 [INFO] Opening main db
2024-06-03T10:09:18+08:00 [INFO] Using git binary path: Some("/Applications/Zed.app/Contents/MacOS/git")
2024-06-03T10:09:18+08:00 [INFO] set environment variables from shell:/usr/local/bin/fish, path:/opt/go/bin:/Users/xsh/go/bin:/opt/homebrew/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin
2024-06-03T10:09:18+08:00 [ERROR] crates/theme/src/settings.rs:432: theme not found: Catppuccin Macchiato
2024-06-03T10:09:18+08:00 [INFO] extensions updated. loading 5, reloading 0, unloading 0
2024-06-03T10:09:18+08:00 [INFO] Opening main db
2024-06-03T10:09:18+08:00 [INFO] building git repository, `.git` path in the worktree: ".git"
2024-06-03T10:09:19+08:00 [INFO] Opening main db
2024-06-03T10:09:19+08:00 [INFO] set status on client 0: Authenticating
2024-06-03T10:09:19+08:00 [INFO] Opening main db
2024-06-03T10:09:19+08:00 [INFO] set status on client 79320: Connecting
2024-06-03T10:09:19+08:00 [INFO] Initializing default prettier with plugins {}
2024-06-03T10:09:19+08:00 [INFO] starting language servers for Go: gopls
2024-06-03T10:09:19+08:00 [INFO] starting language server "gopls", path: "/Users/xsh/fm/fm-suggest", id: 1
2024-06-03T10:09:19+08:00 [INFO] Initializing default prettier with plugins {}
2024-06-03T10:09:19+08:00 [INFO] starting language servers for Go: gopls
2024-06-03T10:09:19+08:00 [ERROR] crates/workspace/src/persistence/model.rs:313: Deserializer does not exist for item kind: diagnostics
2024-06-03T10:09:19+08:00 [INFO] found user-installed language server for Go. path: "/Users/xsh/go/bin/gopls", arguments: ["-mode=stdio"]
2024-06-03T10:09:19+08:00 [INFO] starting language server. binary path: "/Users/xsh/go/bin/gopls", working directory: "/Users/xsh/fm/fm-suggest", args: ["-mode=stdio"]
2024-06-03T10:09:19+08:00 [INFO] Language server with id 1 sent unhandled notification window/logMessage:
{
  "type": 1,
  "message": "2024/06/03 10:09:19 creating temp dir: mkdir /var/folders/d9/h1ryx87j3pq8gcx7knm2xssh0000gn/T/\n\u001b[?2004l/gopls-56436.1: no such file or directory\n"
}
2024-06-03T10:09:19+08:00 [INFO] Node runtime install_if_needed
2024-06-03T10:09:19+08:00 [INFO] Initializing default prettier with plugins {}
2024-06-03T10:09:19+08:00 [INFO] starting language servers for Go: gopls
2024-06-03T10:09:20+08:00 [INFO] connected to rpc endpoint https://collab.zed.dev/rpc
2024-06-03T10:09:21+08:00 [INFO] starting language server. binary path: "/Users/xsh/Library/Application Support/Zed/node/node-v18.15.0-darwin-x64/bin/node", working directory: "/", args: ["/Users/xsh/Library/Application Support/Zed/copilot/copilot-v0.5.0/dist/agent.js", "--stdio"]
2024-06-03T10:09:21+08:00 [INFO] add connection to peer
2024-06-03T10:09:21+08:00 [INFO] add_connection;
2024-06-03T10:09:21+08:00 [INFO] waiting for server hello
2024-06-03T10:09:21+08:00 [INFO] got server hello
2024-06-03T10:09:21+08:00 [INFO] set status to connected (connection id: ConnectionId { owner_id: 0, id: 0 }, peer id: PeerId { owner_id: 440, id: 1820744 })
2024-06-03T10:09:21+08:00 [INFO] set status on client 79320: Connected { peer_id: PeerId { owner_id: 440, id: 1820744 }, connection_id: ConnectionId { owner_id: 0, id: 0 } }
2024-06-03T10:09:21+08:00 [ERROR] crates/lsp/src/lsp.rs:360: cannot read LSP message headers
2024-06-03T10:09:21+08:00 [ERROR] crates/lsp/src/lsp.rs:382: Broken pipe (os error 32)
2024-06-03T10:09:21+08:00 [ERROR] crates/lsp/src/lsp.rs:779: server shut down
2024-06-03T10:09:24+08:00 [WARN] Generic lsp request to gopls failed: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-06-03T10:09:24+08:00 [ERROR] crates/project/src/project.rs:7172: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-06-03T10:09:25+08:00 [WARN] Generic lsp request to gopls failed: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go
2024-06-03T10:09:25+08:00 [ERROR] crates/project/src/project.rs:7172: no package metadata for file file:///Users/xsh/fm/fm-suggest/internal/data/reply.go

@E-ricus
Copy link

E-ricus commented Jun 17, 2024

Can someone provide a minimum example repo?

@d1y for me It happens with any repo/project, as simple as a folder with:
go.mod

module example/simple

go 1.22

main.go

package main

import (
	"fmt"
)

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

But just realised it only happens while using gopls from the path, rather than the one downloaded by zed. As soon as I removed from my path gopls, and zed downloads it the Error disappears, and everything works.
If I install gopls again, and zed priorities that one, the error appears again.

Using
gopls: 0.15.3 (both manually installed and by zed)
Zed 0.139.3
Macos 14.5

@setalid
Copy link

setalid commented Sep 23, 2024

I experienced this issue when installing a new version of Go. Installing the same version of go as I have in my go.mod file resolved the issue for me (at least the same minor version). I have no confidence in this solution, but it might be worth testing out.

@cjek420
Copy link

cjek420 commented Oct 8, 2024

Installed Go 1.23 and hit this bug with all my projects which have Go code. Updated go.mod to match the installed version of Go. Made sure the gopls is the one installed by Zed. Nothing helped.
This is with Zed 0.155.2, Go 1.23.2, gopls_0.16.2, MacOS 15.0.1

Please give us away to hide or auto hide the error dialog.

@diwakergupta
Copy link

I'm also hitting this with latest Zed (0.156.0) on Mac, go 1.23.2

Is there a workaround?

@cjek420
Copy link

cjek420 commented Oct 11, 2024

To add more information, when this error message happens Zed consumes 40% of the CPU. When I close all the Go files the error message vanishes and Zed returns an idle state.

@gm0stache
Copy link

same issue!

@diwakergupta
Copy link

I'm also hitting this with latest Zed (0.156.0) on Mac, go 1.23.2

Is there a workaround?

For anyone else that needs a workaround, I found one! Starting Zed from the command line works for me 🤷🏽 Starting it directly via Spotlight or Applications results in this error.

@notpeter
Copy link
Member

notpeter commented Nov 5, 2024

For folks running into this, can you confirm that you don't have multiple copies of gopls installed (perhaps one via homebrew/apt and one via go's package manager). It may be an older version of gopls acting up.

Please see the docs for example instructions for uninstalling and installing the most up to date version of gopls. https://zed.dev/docs/languages/go

For anyone else that needs a workaround, I found one! Starting Zed from the command line works for me 🤷🏽 Starting it directly via Spotlight or Applications results in this error.

This is likely due to slightly different PATH environment variables between when Zed is launched from Finder and launched from your shell. It may be the the Gui launched zed is getting an old homebrew version, while the shell is getting another.

(If this doesn't solved your issue, my apologies for giving false hope ;)

@cjek420
Copy link

cjek420 commented Nov 6, 2024

I only have one copy of gopls which is the one installed by Zed,
.../Library/Application Support/Zed/languages/gopls/gopls_0.16.2 ** telemetry **
.../Library/Application Support/Zed/languages/gopls/gopls_0.16.2 -mode=stdio

With the latest version of Zed 0.159.10 this is no longer an issue.

@notpeter
Copy link
Member

notpeter commented Nov 6, 2024

@xushuhui Are you still seeing this with the latest Zed?
Or is this OK to close?

@rustatian
Copy link

rustatian commented Nov 12, 2024

Having this issue on a clean macOS + latest Zed install. Tried to remove the gopls from the GOBIN (to leave only 1 gopls downloaded by Zed), does not help.
The only solution for me is to run Zed from the terminal.

I can guess that the problem is in some envs which are not populated via the regular start. Because after starting from the terminal I see in logs that Zed found user-installed language server for gopls in PATH which does not appear on a regular start. I'm using Fish shell if that helps.

@notpeter
Copy link
Member

@rustatian

  1. Can you provide a copy of the PATH shown in your Zed logs?
  2. Does it differ when you launch via Terminal or via Finder?

Similarly can you compare echo $PATH between your terminal session where you launch zed and echo $PATH in a terminal inside a Zed run that you spawned via Finder?

I ask because I just noticed that @xushuhui's logs has the following:

set environment variables from shell:/usr/local/bin/fish, path:/opt/go/bin:/Users/xsh/go/bin:...

I think their issue is because /opt/go/bin comes first, so if /opt/go/bin/gopls exists it will be used instead of ~/go/bin/gopls (old version, old errors).

ZSH users would have a .zshrc that contains a export PATH="$PATH:$HOME/go/bin". Bash users would use .bashrc and .bash_profile for this.

I'm curious where you are adding ~/go/bin to your path for Fish:

  • fish_add_path $HOME/go/bin in /etc/fish/conf.d/
  • fish_add_path $HOME/go/bin in ~/.config/fish/config.fish
  • set -gx PATH $PATH $HOME/go/bin in one/both of those

Or: did you run fish_add_path $HOME/go/bin once in an interactive shell and are relying on something in ~/.config/fish/fish_variables that looks like:

  • SETUVAR fish_user_paths:/home/username/go/bin\x1e/some/other/path instead?

@rustatian
Copy link

Hey @notpeter 👋
These are paths for the regular start (Application):

/Users/.../go_path/bin 
/Users/valery/.cargo/bin 
/opt/homebrew/bin 
/usr/local/bin 
/System/Cryptexes/App/usr/bin 
/usr/bin 
/bin 
/usr/sbin 
/sbin 
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin /Library/Apple/usr/bin

And these are when started from the terminal:

/Users/.../go_path/bin 
/Users/valery/.cargo/bin 
/opt/homebrew/bin 
/usr/local/bin 
/System/Cryptexes/App/usr/bin 
/usr/bin 
/bin 
/usr/sbin 
/sbin 
/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin /Library/Apple/usr/bin 
/Applications/kitty.app/Contents/MacOS

The repeated error in logs is: [ERROR] no package metadata for file file + filepath.
All Fish env variables are in the .config/fish/fish_variables file.

I'm curious where you are adding ~/go/bin to your path for Fish:

I'm using only fish_add_path. No additional envs configuration in the config.fish

Or: did you run fish_add_path $HOME/go/bin once in an interactive shell and are relying on something in ~/.config/fish/fish_variables that looks like.

Yep, correct.

@rustatian
Copy link

@notpeter After the recent update (0.161.1) everything works w/o any problem.

@diwakergupta
Copy link

@notpeter the problem persists for me with Zed 0.161.2

Status at the bottom keeps saying "Error loading workspace: packages.Load error JSON decoding failed ..."

And the log doesn't have much more than this:

2024-11-14T17:43:51.751139-05:00 [WARN] Generic lsp request to gopls failed: no package metadata for file <filename>
2024-11-14T17:43:52.901271-05:00 [WARN] Generic lsp request to gopls failed: no package metadata for file <filename>
2024-11-14T17:43:52.91782-05:00 [ERROR] no package metadata for file <filename>

Could you please reopen this issue as it's very much not fixed. Note that starting from command line workaround still works, and that the log contains the same warns / error as above.

@notpeter
Copy link
Member

@diwakergupta Please open a clean issue with steps to reproduce and your installation details (versions of go, version of zed, gopls path, zed version, etc).

@rustatian
Copy link

@notpeter Hard to say how, but the problem returned. Just restarted Zed (even w/o restarting MacBook) and here you are 😃
The report is actually the same.

@notpeter notpeter reopened this Nov 25, 2024
@notpeter
Copy link
Member

I think this has got to be a fish-specific thing where we are somehow loading the environment differently depending on whether it's launched from the command-line, respawned when updates are applied / zed: reload workspace and launched from Finder. Perhaps this is a login-shell / non-login shell thing.

@rustatian Can you confirm that you don't have gopls installed via homebrew and in ~/go/bin simultaneously running brew uninstall gopls as suggested above? https://zed.dev/docs/languages/go

@rustatian Does the issue recur if you quit Zed and launch from the command line? (e.g. does it only happen when you spawn Zed via Finder or via in-app reload?)

@rustatian
Copy link

Fish is the default shell in my system (chsh -s) for both, root and me. I don't have gopls installed, either in the GOBIN directory or somewhere else (except Zed's default path, for sure).
When I start Zed by clicking on the icon, I see this error about invalid character. If I start Zed from the terminal, then everything is ok.
If I start Zed by clicking on the icon, and then use zed: reload workspace - the issue goes away (even if I see it initially when starting) as well.

@gm0stache
Copy link

same setup and behavior for me!

@alfredosa
Copy link

workspace: reload fixes this somehow. It gets corrupted over time.

@jnardiello
Copy link

Same here, turns out I'm hitting the same very weird error.

@gm0stache
Copy link

workspace: reload fixes the issue for me too!

my system info:

Zed: v0.165.4 (Zed)
OS: macOS 15.2.0
Memory: 16 GiB
Architecture: aarch64

@dschier-wtd
Copy link

dschier-wtd commented Dec 29, 2024

I fiddled around with this a bit. Indeed it seems to be related to the shell. When using ZSH, verything works as expected. using fish, this error occurs.

Also, this error does not occur when starting from command line, but only when using Spotlight or Launchpas on MacOS.

Using:

  • MacOS: 15.2 (24C101)
  • Zed: Zed 0.166.1 – /Applications/Zed.app
  • Go: go version go1.23.4 darwin/arm64 (via Go installer, not brew)
  • gopls: golang.org/x/tools/gopls v0.17.1
  • fish: fish, version 3.7.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [core label] go Go programming language support language An umbrella label for all programming languages syntax behaviors
Projects
None yet
Development

No branches or pull requests