Skip to content

Commit

Permalink
check file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
visu-suganya committed Feb 21, 2023
1 parent 00e9db7 commit b4655f0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gobco-format.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ func main() {
isUpdateJson := flag.Bool("isUpdateJson", false, "")
flag.Parse()

if !fileExists(*packageName + "/branch-cover.json") {
return
}

currentContent, err := ioutil.ReadFile(*packageName + "/branch-cover.json")

if err != nil {
log.Fatal("Error when opening file: ", err)
}
Expand Down Expand Up @@ -223,3 +228,10 @@ func createDataForXmlfile(branchCoverageDataCoverage BranchCoverageDataCoverage)
}
return lineToCoverElemList
}

// fileExists checks if a file exists and is not a directory before we
// try using it to prevent further errors.
func fileExists(filename string) bool {
_, err := os.Stat(filename)
return !os.IsNotExist(err)
}

0 comments on commit b4655f0

Please sign in to comment.