Repository navigation
fix(display): report files as [] instead of null when a pull produces none - #2175
Merged
TerryHowe merged 1 commit intoSep 21, 2026
Merged
Conversation
… none
model.NewPull passes the caller's slice straight into the `files` field, and
Pulled.Files() returns slices.Clone of a nil slice, which is also nil. A pull
that produced no files therefore marshalled the field as null, and a
go-template taking its length failed:
error calling len: len of nil pointer
OnFilePulled only fires for layers carrying org.opencontainers.image.title,
so an artifact with no titled layer reaches this path.
This is the pull half of the same inconsistency fixed for push in oras-project#2170: the
repositories, tags and referrers lists all report [] when empty, so the same
template shape worked for every command except pull.
Initialise the slice to []File{} when nil, matching the style used for
referenceAsTags.
Add regression tests at each layer the value passes through, each confirmed
to fail before this change:
- model: NewPull marshals files as [] for nil and empty input, comparing
the raw JSON so null and [] are told apart
- json handler: a pull with no files reports files as []
- template handler: {{len .files}} renders 0 instead of erroring
The existing template TestPullHandler_Render_noFiles uses {{range .files}},
which tolerates either form, and still passes.
Signed-off-by: Akshita <[email protected]>
akshita317
requested review from
TerryHowe,
Wwwsylvia,
sabre1041,
sajayantony and
shizhMSFT
as code owners
September 19, 2026 12:12
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2175 +/- ##
=======================================
Coverage 87.81% 87.82%
=======================================
Files 139 139
Lines 5689 5691 +2
=======================================
+ Hits 4996 4998 +2
Misses 413 413
Partials 280 280 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Refs #2169 — the
pullhalf.A note on that issue: it tracked both halves, but it auto-closed when #2170 merged because I used a closing keyword there while deliberately fixing only
push. That was my mistake; happy to reopen it if you would rather track the remaining half there.Problem
model.NewPullpasses the caller's slice straight intofiles, andPulled.Files()returnsslices.Cloneof a nil slice — which is also nil. So a pull that produced no files marshals as:{ "files": null }and a go-template taking its length fails outright:
OnFilePulledonly fires for layers carryingorg.opencontainers.image.title, so an artifact with no titled layer reaches this path.This is the same inconsistency fixed for
pushin #2170:repositories,tagsandreferrersall report[]when empty, so the same template shape worked for every command exceptpull.Fix
func NewPull(digestReference string, files []File) any { + if files == nil { + files = []File{} + }NewPullis the single serialisation boundary — both the JSON and template handlers call it withph.pulled.Files()— so one guard covers both.Tests
Written first and confirmed failing on
main:mainmodelTestNewPull_files(nil / empty / one file)files = null, want []jsonTestPullHandler_Render_noFilesfiles = null, want []templateTestPullHandler_Render_noFilesLen({{len .files}})len of nil pointerThe model test compares the raw JSON value, so it distinguishes
nullfrom[]rather than accepting either.Compatibility
For a pull with no files,
--format jsonchangesfilesfromnullto[]. Nothing depended onnull: the templateTestPullHandler_Render_noFilesadded in #2168 uses{{range .files}}, which tolerates either form and still passes, and the e2e suite only ranges over the field.go test ./...,gofmtandgo vetare clean.