Skip to content

NewHistogramReporter swallows write errors (return nil instead of return err) #756

@queelius

Description

@queelius

Bug Description

In lib/reporters.go, the NewHistogramReporter function has a typo where a write error is silently swallowed:

for i, count := range h.Counts {
    ratio := float64(count) / float64(h.Total)
    lo, hi := h.Buckets.Nth(i)
    pad := strings.Repeat("#", int(ratio*75))
    _, err = fmt.Fprintf(tw, "[%s,\t%s]\t%d\t%.2f%%\t%s\n", lo, hi, count, ratio*100, pad)
    if err != nil {
        return nil  // BUG: should be `return err`
    }
}

The header write at line 38 correctly returns err, but the bucket write at line 47 returns nil, swallowing the error.

Impact

Write errors (e.g., broken pipe, disk full) during histogram bucket output are silently discarded. The caller receives no indication that the report was incomplete.

Fix

Change return nil to return err.

PR forthcoming.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions