diff --git a/cmd/vulnreport/main.go b/cmd/vulnreport/main.go index a3c8afed..d3dbaea6 100644 --- a/cmd/vulnreport/main.go +++ b/cmd/vulnreport/main.go @@ -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() } @@ -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