Repository navigation
fix(list): emit [] instead of null for empty JSON list results - #208
Merged
Merged
Conversation
When GetDependenciesWithDB returns a nil slice, json.Encode emits `null`. Downstream consumers expecting a JSON array fail schema validation. Coalesce to empty slice before encoding. Fixes git-pkgs#207.
andrew
requested changes
May 26, 2026
andrew
left a comment
Contributor
There was a problem hiding this comment.
Can we get a test for this as well please
Contributor
Author
|
I've added unit tests for |
There was a problem hiding this comment.
Pull request overview
This PR fixes JSON output for the list command so empty dependency results are emitted as [] instead of null, matching downstream schema expectations for array output.
Changes:
- Coalesces nil dependency slices to an empty slice before JSON encoding.
- Adds tests covering nil, empty, and non-empty dependency JSON output.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
cmd/list.go |
Ensures outputListJSON encodes nil dependency slices as empty JSON arrays. |
cmd/list_test.go |
Adds unit coverage for JSON serialization behavior of list output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
andrew
approved these changes
May 27, 2026
Contributor
|
Thanks! |
This was referenced May 27, 2026
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.
Description
When
GetDependenciesWithDBreturns a nil slice (no manifests found), Go'sjson.Encodeemitsnullrather than[].Downstream consumers that wrap the output (e.g.
printf '{"dependencies": '; git-pkgs list --format json; printf '}') end up with{"dependencies": null}, which fails schema validation against"type": "array".Fix
Add a nil check before encoding — coalesce to an empty slice so
json.Encodeproduces[].Fixes #207