Skip to content

Commit d8ed96e

Browse files
committed
Describe available platforms when no match
Signed-off-by: Stepan Koltsov <[email protected]>
1 parent 25d70d7 commit d8ed96e

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

internal/manifest/oci_index.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"math"
99
"runtime"
1010
"slices"
11+
"strings"
1112

1213
platform "github.com/containers/image/v5/internal/pkg/platform"
1314
compression "github.com/containers/image/v5/pkg/compression/types"
@@ -229,6 +230,26 @@ func (ic instanceCandidate) isPreferredOver(other *instanceCandidate, preferGzip
229230
panic("internal error: invalid comparison between two candidates") // This should not be reachable because in all calls we make, the two candidates differ at least in manifestPosition.
230231
}
231232

233+
func (index *OCI1IndexPublic) descOciPlatforms() string {
234+
if len(index.Manifests) == 0 {
235+
return "no platforms"
236+
}
237+
238+
var b strings.Builder
239+
for i, d := range index.Manifests {
240+
if i > 0 {
241+
b.WriteString(", ")
242+
}
243+
if d.Platform != nil {
244+
imagePlatform := ociPlatformClone(*d.Platform)
245+
b.WriteString(fmt.Sprintf("arch=%q os=%q variant=%q", imagePlatform.Architecture, imagePlatform.OS, imagePlatform.Variant))
246+
} else {
247+
b.WriteString("any")
248+
}
249+
}
250+
return b.String()
251+
}
252+
232253
// chooseInstance is a private equivalent to ChooseInstanceByCompression,
233254
// shared by ChooseInstance and ChooseInstanceByCompression.
234255
func (index *OCI1IndexPublic) chooseInstance(ctx *types.SystemContext, preferGzip types.OptionalBool) (digest.Digest, error) {
@@ -254,7 +275,8 @@ func (index *OCI1IndexPublic) chooseInstance(ctx *types.SystemContext, preferGzi
254275
if bestMatch != nil {
255276
return bestMatch.digest, nil
256277
}
257-
return "", fmt.Errorf("no image found in image index for architecture %q, variant %q, OS %q", wantedPlatforms[0].Architecture, wantedPlatforms[0].Variant, wantedPlatforms[0].OS)
278+
return "", fmt.Errorf("no image found in image index for architecture %q, variant %q, OS %q; available platforms: %s", wantedPlatforms[0].Architecture, wantedPlatforms[0].Variant, wantedPlatforms[0].OS,
279+
index.descOciPlatforms())
258280
}
259281

260282
func (index *OCI1Index) ChooseInstanceByCompression(ctx *types.SystemContext, preferGzip types.OptionalBool) (digest.Digest, error) {

0 commit comments

Comments
 (0)