fix(golangci): treat empty stdout as no-issues and surface stderr#189
Merged
Conversation
golangci-lint exits with empty stdout when go/packages cannot load the target — typically a .gno-only directory whose temp .go file imports gno.land/... paths the standard Go loader cannot resolve. Previously the empty body was passed to json.Unmarshal, which failed with "unexpected end of JSON input"; the engine then logged a warn per file in such a package and dominated the CI log. Short-circuit empty (or whitespace-only) stdout to a zero result with no error, and capture stderr separately so a real decode failure carries a truncated stderr snippet for diagnosis. Extract the parsing into decodeGolangciOutput so the empty / valid / malformed branches are unit-testable without spawning the binary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
decode golangci-lint output: unexpected end of JSON inputwarnings for every.gnofile in a package.golangci-lintexits with empty stdout whengo/packagescannot load the target (the common case is a pure-.gnodirectory whose temp.gofile importsgno.land/...paths the standard Go loader cannot resolve). The previous code passed that empty body tojson.Unmarshal, which failed and the engine logged a warn per file.decodeGolangciOutputso empty / valid / malformed branches are unit-testable without spawning the binary.Repro
CI on a pure-
.gnorepo (e.g. gnoswap-labs/gnoswap run 24982317573) shows hundreds ofdecode golangci-lint output for <dir>: unexpected end of JSON inputwarnings — one per.gnofile. After this change those warnings disappear; real decode failures still surface with the stderr snippet attached.Test plan
go build ./...make test(race + shuffle) — all packages passgo test -bench=BenchmarkRun -benchmem -run=^$ -benchtime=3x ./internal/within ±5% ofmaindefault_golangci_test.go: empty / valid / malformed JSON fordecodeGolangciOutput, plus 6 cases forsnippetFollow-up
A separate PR will wire
GOPACKAGESDRIVER=gnoplssogolangci-lintcan actually analyze.gnopackages instead of producing empty output.