Skip to content

Commit a55b1ef

Browse files
authored
chore: return both failures when failed to retrieve an image with a scheme (anchore#1801)
Signed-off-by: Idan Frimark <[email protected]>
1 parent 5f7c791 commit a55b1ef

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

syft/source/source.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,27 @@ func getImageWithRetryStrategy(in Input, registryOptions *image.RegistryOptions)
216216
// We need to determine the image source again, such that this determination
217217
// doesn't take scheme parsing into account.
218218
in.ImageSource = image.DetermineDefaultImagePullSource(in.UserInput)
219-
img, err = stereoscope.GetImageFromSource(ctx, in.UserInput, in.ImageSource, opts...)
219+
img, userInputErr := stereoscope.GetImageFromSource(ctx, in.UserInput, in.ImageSource, opts...)
220220
cleanup = func() {
221221
if err := img.Cleanup(); err != nil {
222222
log.Warnf("unable to cleanup image=%q: %w", in.UserInput, err)
223223
}
224224
}
225-
return img, cleanup, err
225+
if userInputErr != nil {
226+
// Image retrieval failed on both tries, we will want to return both errors.
227+
return nil, nil, fmt.Errorf(
228+
"scheme %q specified; "+
229+
"image retrieval using scheme parsing (%s) was unsuccessful: %v; "+
230+
"image retrieval without scheme parsing (%s) was unsuccessful: %v",
231+
scheme,
232+
in.Location,
233+
err,
234+
in.UserInput,
235+
userInputErr,
236+
)
237+
}
238+
239+
return img, cleanup, nil
226240
}
227241

228242
func generateDirectorySource(fs afero.Fs, in Input) (*Source, func(), error) {

0 commit comments

Comments
 (0)