Skip to content

here does not function from within a go workspace #14

@mattbnz

Description

@mattbnz

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions