Skip to content

Commit

Permalink
🧹 Change handling of multi asset errors
Browse files Browse the repository at this point in the history
Fixes #1848

Signed-off-by: Christian Zunker <[email protected]>
  • Loading branch information
czunker committed Oct 17, 2023
1 parent 066adec commit dc76af8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
16 changes: 7 additions & 9 deletions explorer/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up
asset := assetList[i]
resolvedAsset, err := im.ResolveAsset(asset)
if err != nil {
return nil, false, err
log.Error().Err(err).Str("asset", asset.Name).Msg("unable to resolve asset")
continue
}

runtime, err := providers.Coordinator.RuntimeFor(asset, providers.DefaultRuntime())
Expand All @@ -202,7 +203,7 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up
Asset: resolvedAsset,
Upstream: upstream,
}); err != nil {
log.Error().Err(err).Msg("unable to connect to asset")
log.Error().Err(err).Str("asset", asset.Name).Msg("unable to connect to asset")
continue
}

Expand All @@ -215,18 +216,15 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up
return nil, false, err
}
for i := range processedAssets {
if processedAssets[i].State == inventory.State_STATE_ERROR {
// we couldn't connect to the asset or something else happened, so skip it for further steps
continue
}
assetCandidates = append(assetCandidates, &assetWithRuntime{
asset: processedAssets[i],
runtime: runtime,
})
}
// TODO: we want to keep better track of errors, since there may be
// multiple assets coming in. It's annoying to abort the scan if we get one
// error at this stage.

// we grab the asset from the connection, because it contains all the
// detected metadata (and IDs)
// assets = append(assets, runtime.Provider.Connection.Asset)
}

// for each asset candidate, we initialize a new runtime and connect to it.
Expand Down
13 changes: 7 additions & 6 deletions providers/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ func ProcessAssetCandidates(runtime *Runtime, connectRes *pp.ConnectRes, upstrea
}
log.Debug().Msgf("resolved %d assets", len(assetCandidates))

if err := detectAssets(runtime, assetCandidates, upstreamConfig); err != nil {
return nil, err
}
detectAssets(runtime, assetCandidates, upstreamConfig)

if platformID != "" {
res, err := filterAssetByPlatformID(assetCandidates, platformID)
Expand All @@ -39,7 +37,7 @@ func ProcessAssetCandidates(runtime *Runtime, connectRes *pp.ConnectRes, upstrea
}

// detectAssets connects to all assets that do not have a platform ID yet
func detectAssets(runtime *Runtime, assetCandidates []*inventory.Asset, upstreamConfig *upstream.UpstreamConfig) error {
func detectAssets(runtime *Runtime, assetCandidates []*inventory.Asset, upstreamConfig *upstream.UpstreamConfig) {
for i := range assetCandidates {
asset := assetCandidates[i]
// If the assets have platform IDs, then we have already connected to them via the
Expand All @@ -50,7 +48,9 @@ func detectAssets(runtime *Runtime, assetCandidates []*inventory.Asset, upstream

// Make sure the provider for the asset is present
if err := runtime.DetectProvider(asset); err != nil {
return err
log.Error().Err(err).Str("asset", asset.Name).Msg("could not detect provider for asset")
asset.State = inventory.State_STATE_ERROR
continue
}

err := runtime.Connect(&pp.ConnectReq{
Expand All @@ -59,12 +59,13 @@ func detectAssets(runtime *Runtime, assetCandidates []*inventory.Asset, upstream
Upstream: upstreamConfig,
})
if err != nil {
log.Error().Err(err).Str("asset", asset.Name).Msg("could not connect to asset")
asset.State = inventory.State_STATE_ERROR
continue
}
// Use the updated asset
assetCandidates[i] = runtime.Provider.Connection.Asset
}
return nil
}

func filterAssetByPlatformID(assetList []*inventory.Asset, selectionID string) (*inventory.Asset, error) {
Expand Down

0 comments on commit dc76af8

Please sign in to comment.