Skip to content

fix: return error from ScanAll when every scan attempt fails - #85

Open
Abhinesh Jha (Abhineshhh) wants to merge 3 commits into
microsoft:mainfrom
Abhineshhh:fix/scanall-error-aggregation
Open

fix: return error from ScanAll when every scan attempt fails#85
Abhinesh Jha (Abhineshhh) wants to merge 3 commits into
microsoft:mainfrom
Abhineshhh:fix/scanall-error-aggregation

Conversation

@Abhineshhh

@Abhineshhh Abhinesh Jha (Abhineshhh) commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Description

ScanAll always returned nil even when every repository or image failed. A total outage still exited 0, and report generation (including the nightly commit) ran against a stale database.

This change tracks real scan outcomes and returns an error only when every attempt fails. Partial success still produces a report from newly scanned images. Images skipped because they already exist (without --update-existing) are not counted as successful attempts.

Related Issue

Fixes #77

Changes

  • Track attempt/failure counts across tag discovery and image scans
  • Continue on partial failure (unchanged)
  • Return an error only when all real scan attempts fail
  • Do not count skipped existing images as attempts
  • Log a summary on partial failure
  • Unit tests for scanStats and ScanAll outcomes (including skip vs. failure)

Checklist

  • task lint passes locally
  • task test passes locally
  • Documentation updated (if applicable)

Stacking

Independent of the Trivy/registry stacks — can merge in any order relative to them.

@maniSbindra Mani Bindra (maniSbindra) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detailed comment added to line 104

Comment thread pkg/usecase/pipeline.go Outdated
}

for _, img := range singleImages {
stats.attempted++

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scanSingleImage returns nil both after a successful scan and when an existing image is skipped because --update-existing is not set. Since attempted is incremented here and failed is incremented only for a non-nil error, skipped images are counted as successful attempts.

For example, if one image is skipped and every image actually scanned fails, the counters still show a partial success and ScanAll returns nil. This appears inconsistent with the intended "all scan attempts failed" behavior.

Consider returning an explicit outcome from scanSingleImage, such as scanned/skipped/failed, and counting only images that were actually scanned. The same issue applies to stats.attempted++ at line 170.

Impact is limited because the nightly workflow passes --update-existing; this mainly affects local runs against an existing database. Non-blocking.

@Abhineshhh Abhinesh Jha (Abhineshhh) Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right ,a skip returned nil and was counted as a successful attempt, so one skipped image plus a total scan outage still looked like partial success.

scanSingleImage now returns (skipped, err). scanStats.record ignores skips, so only images that were actually scanned (or tag-discovery failures) count. TestScanStatsRecord_SkipsAreNotAttempts covers the skipped + all-real-scans-failed case.

Pushed on this branch after rebase onto current main.

ScanAll logged per-image and per-repository errors but always returned
nil, so a total outage still exited successfully and report generation
ran against a stale database (including nightly commits).

Track attempt/failure counts, keep partial-success behavior, and fail
only when all attempts fail. Log a summary on partial failure.

Fixes microsoft#77
scanSingleImage returns nil both on a successful scan and when an
existing image is skipped without --update-existing. Counting those
skips as attempts made a total outage look like partial success.

Record only real scan outcomes. Skips are neither attempts nor
successes.

Addresses review on microsoft#85.
Add stubs for Analyze/GetTags so ScanAll can be tested without
Docker. Prove a skipped existing image does not mask a total
outage, and that tag-discovery and per-image failures aggregate
correctly.

Treat a skip paired with an error as a failed attempt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ScanAll always returns nil even when every scan operation fails

2 participants