Repository navigation
Description
Summary
Report destination errors are swallowed by the table, vertical, Markdown, and CycloneDX reporters. When a writer rejects the report (for example, because its storage is full), reporter.PrintResult returns nil for those formats. JSON, HTML, SARIF, and SPDX correctly return the same error.
This can prevent the CLI from detecting an empty or incomplete output report. The reproduction below uses the real reporter API with an intentionally failing writer; no disk needs to be filled and no network or vulnerability-service access is required.
Environment
- main at eda4d27
- Go 1.27.3, macOS arm64
Reproduction
Save this as internal/reporter/write_failure_repro_test.go and run:
go test ./internal/reporter -run '^TestReportWriteFailure$' -count=1 -vpackage reporter_test
import (
"errors"
"testing"
"github.com/google/osv-scanner/v2/internal/reporter"
"github.com/google/osv-scanner/v2/pkg/models"
)
var errDestinationFull = errors.New("output storage is full")
type failingReportWriter struct { calls int }
func (w *failingReportWriter) Write([]byte) (int, error) {
w.calls++
return 0, errDestinationFull
}
func TestReportWriteFailure(t *testing.T) {
formats := []string{
"json", "table", "vertical", "markdown",
"cyclonedx-1-6", "html", "sarif", "spdx-2-3",
}
for _, format := range formats {
t.Run(format, func(t *testing.T) {
w := &failingReportWriter{}
err := reporter.PrintResult(
&models.VulnerabilityResults{}, format, w, 0, false,
)
t.Logf("writes=%d error=%v", w.calls, err)
if !errors.Is(err, errDestinationFull) {
t.Errorf("destination rejected the report, got error %v", err)
}
})
}
}Actual result
Each format attempts one write:
| Format | Error returned |
|---|---|
| JSON | output storage is full |
| Table | nil |
| Vertical | nil |
| Markdown | nil |
| CycloneDX 1.6 | nil |
| HTML | output storage is full |
| SARIF | output storage is full |
| SPDX 2.3 | output storage is full |
CycloneDX also logs:
WARN Failed to parse package URL: output storage is full
The error is from writing the report, not parsing a package URL.
Expected behavior
Report write failures should propagate to the caller consistently across formats. A successfully completed scan should not conceal a failed report write.
Relevant code
- Table/Markdown reporter ignores the write result on the empty-results path, and also returns nil on the nonempty path.
- Vertical reporter likewise returns nil.
- CycloneDX reporter treats every exporter error as a package-URL warning, including encoding/write errors.
- CLI output handling relies on the returned report-generation error.
Proposed contribution
I would like to contribute a focused fix and regression tests for report destination errors, preserving successful report contents and the existing behavior for unsupported package URLs. Could a maintainer confirm the preferred approach and assign this issue to me?
Activity
VISHNU0906 commentedon Nov 6, 2026
I'd like to take this. I can add write-error propagation for the table, vertical, Markdown, and CycloneDX reporters to match JSON/HTML/SARIF/SPDX, with a regression test using a failing writer.