Skip to content

Commit f213c38

Browse files
committed
Provide more context to artifact inspect errors
1 parent efef2a8 commit f213c38

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

artifact.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,21 @@ import (
1515
"io"
1616
"os"
1717
"reflect"
18+
"slices"
1819
"strings"
1920
"sync"
2021

2122
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
23+
_ "github.com/aquasecurity/trivy/pkg/fanal/analyzer/all"
2224
"github.com/aquasecurity/trivy/pkg/fanal/artifact"
2325
"github.com/aquasecurity/trivy/pkg/fanal/handler"
2426
"github.com/aquasecurity/trivy/pkg/fanal/types"
2527
"github.com/aquasecurity/trivy/pkg/fanal/walker"
2628
v1 "github.com/google/go-containerregistry/pkg/v1"
2729
"github.com/samber/lo"
2830
"github.com/sirupsen/logrus"
29-
"slices"
3031
"golang.org/x/sync/semaphore"
3132

32-
_ "github.com/aquasecurity/trivy/pkg/fanal/analyzer/all"
33-
3433
_ "github.com/castai/image-analyzer/apk"
3534
_ "github.com/castai/image-analyzer/dpkg"
3635
_ "github.com/castai/image-analyzer/rpm"
@@ -128,12 +127,16 @@ func (a Artifact) Inspect(ctx context.Context) (*ArtifactReference, error) {
128127

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

132134
// Check if image artifact info already cached.
133135
cachedArtifactInfo, err := a.getCachedArtifactInfo(ctx, imageKey)
134136
if err != nil && !errors.Is(err, ErrCacheNotFound) {
135-
return nil, err
137+
return nil, fmt.Errorf("unable to access artifact cache: %w", err)
136138
}
139+
137140
var missingImageKey string
138141
if cachedArtifactInfo == nil {
139142
missingImageKey = imageKey
@@ -142,7 +145,7 @@ func (a Artifact) Inspect(ctx context.Context) (*ArtifactReference, error) {
142145
// Find cached layers
143146
cachedLayers, err := a.getCachedLayers(ctx, layerKeys)
144147
if err != nil {
145-
return nil, err
148+
return nil, fmt.Errorf("unable to access layers cache: %w", err)
146149
}
147150
missingLayersKeys := lo.Filter(layerKeys, func(v string, _ int) bool {
148151
_, ok := cachedLayers[v]

0 commit comments

Comments
 (0)