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

here does not function from within a go workspace #14

Open
mattbnz opened this issue Sep 19, 2022 · 2 comments
Open

here does not function from within a go workspace #14

mattbnz opened this issue Sep 19, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request s: accepted

Comments

@mattbnz
Copy link

mattbnz commented Sep 19, 2022

Go 1.18 introduced workspaces (https://go.dev/doc/tutorial/workspaces) defined by a go.work file defined in the parent directory of a module - these are useful for working with private packages, etc.

I have a setup where my buffalo project depends on a private "common" module for my organisation, and therefore I develop within a go workspace using the following directory structure:

matt@argon:~/ws$ ls
common  go.work  web

Where web contains my buffalo project, common is the private module, and go.work defined the go workspace.

Unfortunately attempting to use many buffalo-cli commands within this workspace fails with the following error:

matt@argon:~/ws/web$ buffalo task list
Usage:
  buffalo task [flags]

Aliases:
  task, t, tasks

Flags:
  -h, --help   help for task

ERRO[0000] Error: here.Dir: /home/matt/ws/web: here.cache: /home/matt//ws/web: here.nonGoDir: /home/matt//ws/web: invalid character '{' after top-level value 

The issue appears to be that the here module is unable to handle the JSON returned by go list when executed under a workspace, specifically the output of go list -json -m (called by https://github.com/gobuffalo/here/blob/main/dir.go#L71) returns multiple JSON objects (not in a JSON array!), which then raises the error above when the output is parsed to json.Unmarshal on the following lines...

Example go list output:

matt@argon:~/ws/web$ go list -json -m
{
	"Path": "github.com/MYORG/common",
	"Main": true,
	"Dir": "/home/matt//ws/common",
	"GoMod": "/home/matt//ws/common/go.mod",
	"GoVersion": "1.18"
}
{
	"Path": "github.com/MYORG/web",
	"Main": true,
	"Dir": "/home/matt/ws/web",
	"GoMod": "/home/matt/ws/web/go.mod",
	"GoVersion": "1.18"
}

While arguably this is a go list bug for returning multiple JSON objects outside of a JSON array, the fact that there's a released version of go doing this, to me means that this output format needs to be supported by the here command.

@mattbnz
Copy link
Author

mattbnz commented Sep 19, 2022

According to golang/go#46486 the output of go list -json -m is valid JSON, but needs to be passed to json.Decoder, and the output iterated, rather than passed to json.Unmarshal...

@sio4
Copy link
Member

sio4 commented Sep 19, 2022

Yeah, I will take a look at this issue.

There are many issues reporting about it on the go project and they insist that it is working as intended, it is a JSON stream. :-) I don't agree that the FIXED output of the command go list -json is a JSON stream, but if they have no plan to change this weird behavior, we need to fix it.

[1] https://en.wikipedia.org/wiki/JSON_streaming
[2] golang/go#27655 (comment)

@sio4 sio4 added enhancement New feature or request s: accepted labels Sep 19, 2022
@sio4 sio4 self-assigned this Sep 19, 2022
Fanya249 added a commit to Fanya249/here that referenced this issue Jul 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request s: accepted
Projects
None yet
Development

No branches or pull requests

2 participants