@@ -96,14 +96,17 @@ func ociImportBuild(tags []string, commit, dir, file string) error {
96
96
return err
97
97
}
98
98
99
+ // added to any string errors we generate to add more helpful debugging context for things like the wrong filename, directory, commit ID, etc.
100
+ errFileStr := func (file string ) string { return fmt .Sprintf ("%q (from directory %q in commit %q)" , file , dir , commit ) }
101
+
99
102
// https://github.com/opencontainers/image-spec/blob/v1.0.2/image-layout.md#oci-layout-file
100
103
var layout imagespec.ImageLayout
101
104
if err := readJSONFile (fs , "oci-layout" , & layout ); err != nil {
102
- return fmt .Errorf ("failed reading oci-layout : %w" , err )
105
+ return fmt .Errorf ("failed reading %s : %w" , errFileStr ( "oci-layout" ) , err )
103
106
}
104
107
if layout .Version != "1.0.0" {
105
108
// "The imageLayoutVersion value will align with the OCI Image Specification version at the time changes to the layout are made, and will pin a given version until changes to the image layout are required."
106
- return fmt .Errorf ("unsupported OCI image layout version %q" , layout .Version )
109
+ return fmt .Errorf ("unsupported OCI image layout version %q in %s " , layout .Version , errFileStr ( "oci-layout" ) )
107
110
}
108
111
109
112
var manifestDescriptor imagespec.Descriptor
@@ -112,29 +115,29 @@ func ociImportBuild(tags []string, commit, dir, file string) error {
112
115
// https://github.com/opencontainers/image-spec/blob/v1.0.2/image-layout.md#indexjson-file
113
116
var index imagespec.Index
114
117
if err := readJSONFile (fs , file , & index ); err != nil {
115
- return fmt .Errorf ("failed reading %q : %w" , file , err )
118
+ return fmt .Errorf ("failed reading %s : %w" , errFileStr ( file ) , err )
116
119
}
117
120
if index .SchemaVersion != 2 {
118
- return fmt .Errorf ("unsupported schemaVersion %d in %q " , index .SchemaVersion , file )
121
+ return fmt .Errorf ("unsupported schemaVersion %d in %s " , index .SchemaVersion , errFileStr ( file ) )
119
122
}
120
123
if len (index .Manifests ) != 1 {
121
- return fmt .Errorf ("expected only one manifests entry (not %d) in %q " , len (index .Manifests ), file )
124
+ return fmt .Errorf ("expected only one manifests entry (not %d) in %s " , len (index .Manifests ), errFileStr ( file ) )
122
125
}
123
126
manifestDescriptor = index .Manifests [0 ]
124
127
} else {
125
128
if err := readJSONFile (fs , file , & manifestDescriptor ); err != nil {
126
- return fmt .Errorf ("failed reading %q : %w" , file , err )
129
+ return fmt .Errorf ("failed reading %s : %w" , errFileStr ( file ) , err )
127
130
}
128
131
}
129
132
130
133
if manifestDescriptor .MediaType != imagespec .MediaTypeImageManifest {
131
- return fmt .Errorf ("unsupported mediaType %q in descriptor" , manifestDescriptor .MediaType )
134
+ return fmt .Errorf ("unsupported mediaType %q in descriptor in %s " , manifestDescriptor .MediaType , errFileStr ( file ) )
132
135
}
133
136
if err := manifestDescriptor .Digest .Validate (); err != nil {
134
- return fmt .Errorf ("invalid digest %q: %w" , manifestDescriptor .Digest , err )
137
+ return fmt .Errorf ("invalid digest %q in %s : %w" , manifestDescriptor .Digest , errFileStr ( file ) , err )
135
138
}
136
139
if manifestDescriptor .Size < 0 {
137
- return fmt .Errorf ("invalid size %d in descriptor" , manifestDescriptor .Size )
140
+ return fmt .Errorf ("invalid size %d in descriptor in %s " , manifestDescriptor .Size , errFileStr ( file ) )
138
141
}
139
142
// TODO validate Platform is either unset or matches expected value
140
143
@@ -152,17 +155,17 @@ func ociImportBuild(tags []string, commit, dir, file string) error {
152
155
cs := client .ContentStore ()
153
156
154
157
if err := importOCIBlob (ctx , cs , fs , manifestDescriptor ); err != nil {
155
- return fmt .Errorf ("failed to import manifest blob (%q) : %w" , manifestDescriptor .Digest , err )
158
+ return fmt .Errorf ("failed to import manifest blob %s : %w" , errFileStr ( string ( manifestDescriptor .Digest )) , err )
156
159
}
157
160
var manifest imagespec.Manifest
158
161
if err := readContentJSON (ctx , cs , manifestDescriptor , & manifest ); err != nil {
159
- return fmt .Errorf ("failed to parse manifest (%q) : %w" , manifestDescriptor .Digest , err )
162
+ return fmt .Errorf ("failed to parse manifest %s : %w" , errFileStr ( string ( manifestDescriptor .Digest )) , err )
160
163
}
161
164
162
165
otherBlobs := append ([]imagespec.Descriptor {manifest .Config }, manifest .Layers ... )
163
166
for _ , blob := range otherBlobs {
164
167
if err := importOCIBlob (ctx , cs , fs , blob ); err != nil {
165
- return fmt .Errorf ("failed to import blob (%q) : %w" , blob .Digest , err )
168
+ return fmt .Errorf ("failed to import blob %s : %w" , errFileStr ( string ( blob .Digest )) , err )
166
169
}
167
170
}
168
171
@@ -176,11 +179,11 @@ func ociImportBuild(tags []string, commit, dir, file string) error {
176
179
img2 , err := is .Update (ctx , img , "target" ) // "target" here is to specify that we want to update the descriptor that "Name" points to (if this image name already exists)
177
180
if err != nil {
178
181
if ! errdefs .IsNotFound (err ) {
179
- return fmt .Errorf ("failed to update image %q: %w" , img .Name , err )
182
+ return fmt .Errorf ("failed to update image %q in containerd : %w" , img .Name , err )
180
183
}
181
184
img2 , err = is .Create (ctx , img )
182
185
if err != nil {
183
- return fmt .Errorf ("failed to create image %q: %w" , img .Name , err )
186
+ return fmt .Errorf ("failed to create image %q in containerd : %w" , img .Name , err )
184
187
}
185
188
}
186
189
img = img2 // unnecessary? :)
0 commit comments