Skip to content

fix: route failing scanner commands to stderr - #268

Merged
lindycoder merged 4 commits into
mainfrom
79-route-errors-stderr
Jul 21, 2026
Merged

fix: route failing scanner commands to stderr#268
lindycoder merged 4 commits into
mainfrom
79-route-errors-stderr

Conversation

@lindycoder

@lindycoder lindycoder commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

The scan CLI's failure telemetry reports a command's stderr, not stdout, so scanner failures whose error lands on stdout surface only as a bare exited with non-zero exit status: N. This makes those errors actionable again.

Trivy modules (trivy-fs, trivy-sbom, boost-sca) — the trivy post-processor detects "no language files" by reading trivy's Number of language-specific files … num=0 log line, which reaches it only because the scan command merges stderr into stdout. Simply dropping 2>&1 would regress that (an empty report can't substitute — a clean scan can also be empty; see no_venv). Instead, redirect trivy's logs to a file and emit them to both streams, preserving the real exit code:

$SETUP_PATH/trivy fs … . 2>"$LOG"
ec=$?
cat "$LOG"        # logs -> stdout: post-processor keeps its num= detection, unchanged
cat "$LOG" >&2    # logs -> stderr: the CLI now surfaces hard failures
exit "$ec"        # preserve the exit code (do NOT force exit 0)

semgrep — the Validate rules step now echoes its rejection to stderr (>&2).

osv-scalibr-sbom — dropped the stray 2>&1 on cat result.spdx.json (its post-processor reads the SPDX file, not merged logs, so this is safe).

Validated locally (trivy 0.69.2) across: no-language-files (exit 0, num=0 reaches the post-processor), scanned-clean, and hard failure (exit ≠ 0, real error on stderr). End-to-end dev validation via test-repo PRs to follow.

Part of boostsecurityio/workspace#79
Jira: BOOSTSP-795

lindycoder and others added 4 commits July 17, 2026 22:32
The scan CLI's failure telemetry reports a command's stderr, not stdout. Several
modules routed their real error to stdout, so a failed scan surfaced only
"exited with non-zero exit status: N" to the dashboard, with no actionable detail.

- trivy-fs, trivy-sbom, boost-sca: drop the trailing `2>&1` so trivy's errors
  stay on stderr. The report stays on stdout, so post-processor parsing is
  unaffected (and stdout is now report-only rather than interleaved with logs).
- osv-scalibr-sbom: drop `2>&1` from `cat result.spdx.json`.
- semgrep: route the "Validate rules" rejection to stderr (`>&2`).

The trivy `2>&1` was added in 2024 (dev-registry #127) to surface trivy's
"no supported files" message; that case is now handled upstream by
prescan_checks.sh, which exits on stderr before trivy runs, so the merge is
obsolete and now hides genuine scan-command failures. Verified on dev: the same
forced trivy error is bare with `2>&1` and shows the real message without it.

Part of boostsecurityio/workspace#79
Jira: BOOSTSP-795

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Removing 2>&1 outright regressed the 'no language files' case: the post-processor
detects it by reading trivy's 'Number of language-specific files num=0' log line,
which only reaches it (on stdout) via the merge. Report-emptiness can't substitute
(a clean scan can also be empty — see no_venv).

Instead, redirect trivy's logs to a file, then emit them to BOTH stdout (post-processor,
unchanged) and stderr (CLI surfaces hard failures), preserving the real exit code.

Part of boostsecurityio/workspace#79
Jira: BOOSTSP-795
Adds the same additional-args passthrough trivy-fs has, defaulting to empty (no
behavior change). Makes the module consistent and lets a forced error be injected
for testing the hard-failure path.

Part of boostsecurityio/workspace#79
@lindycoder
lindycoder marked this pull request as ready for review July 20, 2026 13:14
@lindycoder
lindycoder requested a review from a team as a code owner July 20, 2026 13:14
@Franck-Boost

Copy link
Copy Markdown
Contributor

@lindycoder shouldn't the trivy-image and the trivy-image-sbom modules be updated as well ?

@lindycoder

Copy link
Copy Markdown
Contributor Author

@Franck-Boost the fact that those did not have the 2>&1 log merge tells me they might not need it, i'll expand the test to those as well to check, but I would make this a separate change

@Franck-Boost

Franck-Boost commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@lindycoder based on my testing it seems to be fair to not update the trivy-image and trivy-sbom-image for the use case we support. Yet there is another use case that might requires it. I'll create an issue for that.

@lindycoder

Copy link
Copy Markdown
Contributor Author

On the failed checks

  • Azure devops timeout is normal, we don'T have parallelism, the scans succeeded
  • Gitlab had a transient 500

Enough scans have run to prove the happy path is not broken

@lindycoder
lindycoder merged commit b513c34 into main Jul 21, 2026
10 of 12 checks passed
@lindycoder
lindycoder deleted the 79-route-errors-stderr branch July 21, 2026 18:11
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.

3 participants