From 421d7205abe842674312a5986f8644f9bab1c3f3 Mon Sep 17 00:00:00 2001 From: jandelgado Date: Fri, 11 Sep 2020 23:46:39 +0200 Subject: [PATCH] make sure defer runs (linter) (#6) --- main.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 36c3bb3..50959c9 100644 --- a/main.go +++ b/main.go @@ -239,12 +239,16 @@ func convertCoverage(in io.Reader, out io.Writer) error { } func main() { + os.Exit(gcovmain()) +} + +func gcovmain() int { infileName := flag.String("infile", "", "go coverage file to read, default: ") outfileName := flag.String("outfile", "", "lcov file to write, default: ") flag.Parse() if len(flag.Args()) > 0 { flag.Usage() - os.Exit(1) + return 1 } infile := os.Stdin @@ -253,20 +257,24 @@ func main() { if *infileName != "" { infile, err = os.Open(*infileName) if err != nil { - log.Fatalf("error opening input file: %v", err) + log.Printf("error opening input file: %v\n", err) + return 2 } defer infile.Close() } if *outfileName != "" { outfile, err = os.Create(*outfileName) if err != nil { - log.Fatalf("error opening output file: %v", err) + log.Printf("error opening output file: %v\n", err) + return 3 } defer outfile.Close() } err = convertCoverage(infile, outfile) if err != nil { - log.Fatalf("convert: %v", err) + log.Printf("error: convert: %v", err) + return 4 } + return 0 }