Skip to content

Commit

Permalink
Allow --err-first-miss to continue for skipped files (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
tstromberg authored Nov 6, 2024
1 parent affd9b0 commit e61545e
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions pkg/action/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,34 +154,49 @@ func errIfHitOrMiss(frs *sync.Map, kind string, scanPath string, errIfHit bool,
count int
suffix string
)
if frs != nil {
frs.Range(func(_, value any) bool {
if value == nil {
if frs == nil {
return nil
}

filesScanned := 0

frs.Range(func(_, value any) bool {
if value == nil {
return true
}
if fr, ok := value.(*malcontent.FileReport); ok {
if fr.Skipped != "" {
return true
}
if fr, ok := value.(*malcontent.FileReport); ok {
for _, b := range fr.Behaviors {
count++
bMap.Store(b.ID, true)
}
}
return true
})

bMap.Range(func(key, _ any) bool {
if key == nil {
if fr.Error != "" {
return true
}
if k, ok := key.(string); ok {
bList = append(bList, k)
filesScanned++
for _, b := range fr.Behaviors {
count++
bMap.Store(b.ID, true)
}
return true
})
sort.Strings(bList)
}
return true
})

if len(bList) > 0 {
suffix = fmt.Sprintf(": %s", strings.Join(bList, " "))
bMap.Range(func(key, _ any) bool {
if key == nil {
return true
}
if k, ok := key.(string); ok {
bList = append(bList, k)
}
return true
})
sort.Strings(bList)

if len(bList) > 0 {
suffix = fmt.Sprintf(": %s", strings.Join(bList, " "))
}

if filesScanned == 0 {
return nil
}

// Behavioral note: this logic is per-archive or per-file, depending on context
Expand All @@ -190,7 +205,7 @@ func errIfHitOrMiss(frs *sync.Map, kind string, scanPath string, errIfHit bool,
}

if errIfMiss && count == 0 {
return fmt.Errorf("no matching capabilities in %s %s%s", scanPath, kind, suffix)
return fmt.Errorf("no matching capabilities in %q kind=%s suffix=%s", scanPath, kind, suffix)
}
return nil
}
Expand Down

0 comments on commit e61545e

Please sign in to comment.