Skip to content

Commit

Permalink
Return both failuers when failed to retrive an image with a scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
FrimIdan committed May 9, 2023
1 parent 75d625b commit e83805c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions syft/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/anchore/stereoscope"
"github.com/anchore/stereoscope/pkg/image"

"github.com/anchore/syft/internal/log"
"github.com/anchore/syft/syft/artifact"
)
Expand Down Expand Up @@ -216,13 +217,27 @@ func getImageWithRetryStrategy(in Input, registryOptions *image.RegistryOptions)
// We need to determine the image source again, such that this determination
// doesn't take scheme parsing into account.
in.ImageSource = image.DetermineDefaultImagePullSource(in.UserInput)
img, err = stereoscope.GetImageFromSource(ctx, in.UserInput, in.ImageSource, opts...)
img, userInputErr := stereoscope.GetImageFromSource(ctx, in.UserInput, in.ImageSource, opts...)
cleanup = func() {
if err := img.Cleanup(); err != nil {
log.Warnf("unable to cleanup image=%q: %w", in.UserInput, err)
}
}
return img, cleanup, err
if userInputErr != nil {
// Image retrieval failed on both tries, we will want to return both errors.
return nil, nil, fmt.Errorf(
"scheme %q specified; "+
"image retrieval using scheme parsing (%s) was unsuccessful: %v; "+
"image retrieval without scheme parsing (%s) was unsuccessful: %v",
scheme,
in.Location,
err,
in.UserInput,
userInputErr,
)
}

return img, cleanup, nil
}

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

0 comments on commit e83805c

Please # to comment.