Skip to content

Commit

Permalink
Fail gracefully when readFile fails
Browse files Browse the repository at this point in the history
  • Loading branch information
felixjung authored and daveshanley committed Oct 22, 2024
1 parent ea09cc3 commit 8d5c8cd
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions git/read_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,10 @@ func BuildCommitChangelog(commitHistory []*model.Commit,
if len(commitHistory) == c+1 {
newBits = commitHistory[c].Data

// Obtain data from the previous commit
var err []error
oldBits, err = readFile(commitHistory[c].RepoDirectory, fmt.Sprintf("%s~1", commitHistory[c].Hash), commitHistory[c].FilePath)
if err != nil {
return nil, err
}
// Obtain data from the previous commit and fail gracefully, if git
// errors. This might happen when the file does not exist in the git
// history.
oldBits, _ = readFile(commitHistory[c].RepoDirectory, fmt.Sprintf("%s~1", commitHistory[c].Hash), commitHistory[c].FilePath)
} else {
oldBits = commitHistory[c+1].Data
commitHistory[c].OldData = oldBits
Expand Down

0 comments on commit 8d5c8cd

Please sign in to comment.