fix: route failing scanner commands to stderr - #268
Merged
Conversation
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
Contributor
|
@lindycoder shouldn't the trivy-image and the trivy-image-sbom modules be updated as well ? |
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 |
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. |
Contributor
Author
|
On the failed checks
Enough scans have run to prove the happy path is not broken |
Talgarr
approved these changes
Jul 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'sNumber of language-specific files … num=0log line, which reaches it only because the scan command merges stderr into stdout. Simply dropping2>&1would regress that (an empty report can't substitute — a clean scan can also be empty; seeno_venv). Instead, redirect trivy's logs to a file and emit them to both streams, preserving the real exit code:semgrep— theValidate rulesstep now echoes its rejection to stderr (>&2).osv-scalibr-sbom— dropped the stray2>&1oncat 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=0reaches 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