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

fix: read only STDOUT from "go list" #6

Merged
merged 1 commit into from
Jun 25, 2023
Merged

Conversation

daxelrod-rh
Copy link
Contributor

Sometimes, "go list -m -json", outputs valid JSON on STDOUT, but also other messages on STDERR, such as warnings. Restrict ourselves to just parsing the contents of STDOUT to avoid failures while unmarshalling.

As an example of this situation:

$ GOPATH=$HOME/go GOROOT=$HOME/go go list -m -json 1>out.txt 2>err.txt
$ cat out.txt 
{
        "Path": "github.com/rh-mobb/ocm-operator",
        "Main": true,
        "Dir": "/home/daxelrod/projects/ocm-operator",
        "GoMod": "/home/daxelrod/projects/ocm-operator/go.mod",
        "GoVersion": "1.19"
}
$ cat err.txt 
warning: GOPATH set to GOROOT (/home/daxelrod/go) has no effect

Running gomoddirectives under golanci-lint in this situation results in

failed to get module file: unmarshaling error: invalid character 'w' looking for beginning of value: warning: GOPATH set to GOROOT (/home/daxelrod/go) has no effect

without this PR, and a successful run of gomoddirectives with this PR.

Please let me know if you'd like a unit test written for this case. I haven't written one yet because it didn't seem to fit in to the general structure of the other unit tests that already exist.

Thank you very much for gomoddirectives and golangci-lint!

Sometimes, "go list -m -json", outputs valid JSON on STDOUT, but also
other messages on STDERR, such as warnings.

Restrict ourselves to just parsing the contents of STDOUT to avoid
failures while unmarshalling.
@ldez ldez merged commit 21fb70d into ldez:master Jun 25, 2023
@ldez ldez changed the title Read only STDOUT from "go list" fix: read only STDOUT from "go list" Jun 25, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants