Skip to content

Commit

Permalink
cmd/vulnreport: write partially fixed report in fix
Browse files Browse the repository at this point in the history
In vulnreport fix, always write the report even if an error occurs.
This ensures that any progress fix made is not lost.

Change-Id: Iefddf5a175251c2d65f70b7d45ddede109c006f8
Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/506763
Run-TryBot: Tatiana Bradley <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
  • Loading branch information
tatianab committed Jun 30, 2023
1 parent 4ab276f commit d41b7b7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cmd/vulnreport/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,15 @@ func fix(ctx context.Context, filename string, ghsaClient *ghsa.Client, force bo
if err := r.CheckFilename(filename); err != nil {
return err
}

// We may make partial progress on fixing a report, so write the
// report even if a fatal error occurs somewhere.
defer func() {
if err := r.Write(filename); err != nil {
errlog.Println(err)
}
}()

if lints := r.Lint(); force || len(lints) > 0 {
r.Fix()
}
Expand All @@ -740,11 +749,6 @@ func fix(ctx context.Context, filename string, ghsaClient *ghsa.Client, force bo
}
}

// Write unconditionally in order to format.
if err := r.Write(filename); err != nil {
return err
}

if !r.IsExcluded() {
if err := writeOSV(r); err != nil {
return err
Expand Down

0 comments on commit d41b7b7

Please sign in to comment.