Skip to content

Commit

Permalink
chore: add prefix to image errors (#5601)
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <knqyf263@gmail.com>
  • Loading branch information
knqyf263 committed Nov 20, 2023
1 parent ed0022b commit c866f1c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
8 changes: 4 additions & 4 deletions pkg/commands/artifact/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
// Standalone
//////////////

// initializeDockerScanner is for container image scanning in standalone mode
// initializeImageScanner is for container image scanning in standalone mode
// e.g. dockerd, container registry, podman, etc.
func initializeDockerScanner(ctx context.Context, imageName string, artifactCache cache.ArtifactCache,
func initializeImageScanner(ctx context.Context, imageName string, artifactCache cache.ArtifactCache,
localArtifactCache cache.LocalArtifactCache, imageOpt types.ImageOptions, artifactOption artifact.Option) (
scanner.Scanner, func(), error) {
wire.Build(scanner.StandaloneDockerSet)
Expand Down Expand Up @@ -67,9 +67,9 @@ func initializeVMScanner(ctx context.Context, filePath string, artifactCache cac
// Client/Server
/////////////////

// initializeRemoteDockerScanner is for container image scanning in client/server mode
// initializeRemoteImageScanner is for container image scanning in client/server mode
// e.g. dockerd, container registry, podman, etc.
func initializeRemoteDockerScanner(ctx context.Context, imageName string, artifactCache cache.ArtifactCache,
func initializeRemoteImageScanner(ctx context.Context, imageName string, artifactCache cache.ArtifactCache,
remoteScanOptions client.ScannerOption, imageOpt types.ImageOptions, artifactOption artifact.Option) (
scanner.Scanner, func(), error) {
wire.Build(scanner.RemoteDockerSet)
Expand Down
8 changes: 4 additions & 4 deletions pkg/commands/artifact/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
// imageStandaloneScanner initializes a container image scanner in standalone mode
// $ trivy image alpine:3.15
func imageStandaloneScanner(ctx context.Context, conf ScannerConfig) (scanner.Scanner, func(), error) {
s, cleanup, err := initializeDockerScanner(ctx, conf.Target, conf.ArtifactCache, conf.LocalArtifactCache,
s, cleanup, err := initializeImageScanner(ctx, conf.Target, conf.ArtifactCache, conf.LocalArtifactCache,
conf.ArtifactOption.ImageOption, conf.ArtifactOption)
if err != nil {
return scanner.Scanner{}, func() {}, xerrors.Errorf("unable to initialize a docker scanner: %w", err)
return scanner.Scanner{}, func() {}, xerrors.Errorf("unable to initialize an image scanner: %w", err)
}
return s, cleanup, nil
}
Expand All @@ -34,10 +34,10 @@ func archiveStandaloneScanner(ctx context.Context, conf ScannerConfig) (scanner.
// $ trivy image --server localhost:4954 alpine:3.15
func imageRemoteScanner(ctx context.Context, conf ScannerConfig) (
scanner.Scanner, func(), error) {
s, cleanup, err := initializeRemoteDockerScanner(ctx, conf.Target, conf.ArtifactCache, conf.ServerOption,
s, cleanup, err := initializeRemoteImageScanner(ctx, conf.Target, conf.ArtifactCache, conf.ServerOption,
conf.ArtifactOption.ImageOption, conf.ArtifactOption)
if err != nil {
return scanner.Scanner{}, nil, xerrors.Errorf("unable to initialize the remote docker scanner: %w", err)
return scanner.Scanner{}, nil, xerrors.Errorf("unable to initialize a remote image scanner: %w", err)
}
return s, cleanup, nil
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/commands/artifact/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/fanal/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package image

import (
"context"
"fmt"
"strings"

"github.com/google/go-containerregistry/pkg/name"
Expand Down Expand Up @@ -50,6 +51,7 @@ func NewContainerImage(ctx context.Context, imageName string, opt types.ImageOpt
// Return v1.Image if the image is found
return img, cleanup, nil
}
err = multierror.Prefix(err, fmt.Sprintf("%s error:", src))
errs = multierror.Append(errs, err)
}

Expand Down

0 comments on commit c866f1c

Please sign in to comment.