oras-project / oras

OCI registry client - managing content like artifacts, images, packages
https://oras.land
Apache License 2.0
1.44k stars 174 forks source link

refactor: No error return for print #1375

Closed TerryHowe closed 4 months ago

TerryHowe commented 4 months ago

What this PR does / why we need it:

I don't think we should consider print errors a problem most of the time and we should manage the output of the error to print only once.

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 84.81%. Comparing base (101cf17) to head (2acae64).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1375 +/- ## ========================================== + Coverage 84.75% 84.81% +0.06% ========================================== Files 104 104 Lines 3712 3715 +3 ========================================== + Hits 3146 3151 +5 + Misses 338 336 -2 Partials 228 228 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

qweeah commented 4 months ago

If && p.errored == nil is not required, then errored can be removed from the printer like:

// Println prints objects concurrent-safely with newline.
func (p *Printer) Println(a ...any) error {
    p.lock.Lock()
    defer p.lock.Unlock()
    _, err := fmt.Fprintln(p.out, a...)
    if err != nil  {
        err = fmt.Errorf("display output error: %w", err)
        _, _ = fmt.Fprint(os.Stderr, err)
    }
        return err
}
TerryHowe commented 4 months ago

Last commit only contains improved test errors