Repository navigation
fix: preserve json output for empty results - #248
Conversation
andrew
left a comment
There was a problem hiding this comment.
The pattern is right (move the empty check into the text branch, nonNilSlice so the encoder emits [] not null) and the test is good, but coverage is incomplete for a PR that closes #233.
The issue explicitly names six files; this fixes three (search.go, log.go, notes.go) plus vulns log, but skips:
cmd/blame.go:53cmd/tree.go:66cmd/outdated.go:82,163
The issue also says there may be more. The same if len(x) == 0 { print text; return nil } before the format switch appears in:
cmd/diff.go:127cmd/show.go:59cmd/stale.go:49cmd/where.go:148cmd/history.go:85cmd/licenses.go:130cmd/integrity.go:100,266cmd/vulns.go:417,461,1251,1620,1732,1989
Since nonNilSlice is already in place and the change is mechanical, please cover at least the three files named in the issue, and ideally the rest so #233 can actually close.
Heads up: cmd/helpers.go will conflict with #251 (both insert at the same spot) — whichever lands second will need a rebase.
|
Updated the empty JSON fix to cover the remaining commands called out in the review: blame, tree, outdated, diff, show, stale, and where. Verified with:
|
andrew
left a comment
There was a problem hiding this comment.
Thanks for the follow-up — all six files named in #233 are now covered plus diff/show/stale/where, and the table-driven test is a nice guard.
history.go, licenses.go, integrity.go, and the remaining vulns.go sites still have the same pattern; I'll open a follow-up issue for those rather than block this further.
Heads up #251 is still open, so whichever lands second will need a small rebase around cmd/helpers.go.
Summary
--format=jsonresponses as JSON arrays when result sets are emptysearch,log, and notes JSON outputTesting
go test ./cmdgo test ./...go build ./...go tool golangci-lint run ./...git-pkgs search definitely-not-present --format=jsonCloses #233