Skip to content

Commit

Permalink
Provide more context to artifact inspect errors
Browse files Browse the repository at this point in the history
  • Loading branch information
domust committed Nov 26, 2024
1 parent efef2a8 commit 2a5b153
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ import (
"io"
"os"
"reflect"
"slices"
"strings"
"sync"

"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
_ "github.com/aquasecurity/trivy/pkg/fanal/analyzer/all"
"github.com/aquasecurity/trivy/pkg/fanal/artifact"
"github.com/aquasecurity/trivy/pkg/fanal/handler"
"github.com/aquasecurity/trivy/pkg/fanal/types"
"github.com/aquasecurity/trivy/pkg/fanal/walker"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/samber/lo"
"github.com/sirupsen/logrus"
"slices"
"golang.org/x/sync/semaphore"

_ "github.com/aquasecurity/trivy/pkg/fanal/analyzer/all"

_ "github.com/castai/image-analyzer/apk"
_ "github.com/castai/image-analyzer/dpkg"
_ "github.com/castai/image-analyzer/rpm"
Expand Down Expand Up @@ -128,12 +127,16 @@ func (a Artifact) Inspect(ctx context.Context) (*ArtifactReference, error) {

// Convert image ID and layer IDs to cache keys
imageKey, layerKeys, layerKeyMap := a.calcCacheKeys(imageID, diffIDs)
a.log.Debugf("image key: %s", imageKey)
a.log.Debugf("layer keys: %v", layerKeys)
a.log.Debugf("layer key map: %v", layerKeyMap)

// Check if image artifact info already cached.
cachedArtifactInfo, err := a.getCachedArtifactInfo(ctx, imageKey)
if err != nil && !errors.Is(err, ErrCacheNotFound) {
return nil, err
return nil, fmt.Errorf("unable to access artifact cache: %w", err)
}

var missingImageKey string
if cachedArtifactInfo == nil {
missingImageKey = imageKey
Expand All @@ -142,7 +145,7 @@ func (a Artifact) Inspect(ctx context.Context) (*ArtifactReference, error) {
// Find cached layers
cachedLayers, err := a.getCachedLayers(ctx, layerKeys)
if err != nil {
return nil, err
return nil, fmt.Errorf("unable to access layers cache: %w", err)
}
missingLayersKeys := lo.Filter(layerKeys, func(v string, _ int) bool {
_, ok := cachedLayers[v]
Expand Down

0 comments on commit 2a5b153

Please sign in to comment.