Skip to content

Commit

Permalink
Fix for #33
Browse files Browse the repository at this point in the history
The issue was multiple errors being sent down a channel that stops listening after one error, all errors are now packed up and sent using `errors.Join()`

Signed-off-by: Dave Shanley <[email protected]>
  • Loading branch information
daveshanley committed Apr 28, 2023
1 parent af47fd0 commit 8bb3328
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions git/read_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package git

import (
"bytes"
"errors"
"fmt"
"github.com/araddon/dateparse"
"github.com/pb33f/libopenapi"
Expand Down Expand Up @@ -128,7 +129,7 @@ func PopulateHistoryWithChanges(commitHistory []*model.Commit, limit int,
func BuildCommitChangelog(commitHistory []*model.Commit,
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError) ([]*model.Commit, []error) {

var errors []error
var changeErrors []error
var cleaned []*model.Commit

for c := len(commitHistory) - 1; c > -1; c-- {
Expand All @@ -151,22 +152,21 @@ func BuildCommitChangelog(commitHistory []*model.Commit,

if err != nil {
model.SendProgressError("building models", fmt.Sprintf("unable to parse original document: %s", err.Error()), errorChan)
errors = append(errors, err)
changeErrors = append(changeErrors, err)
}
newDoc, err = libopenapi.NewDocument(newBits)
if err != nil {
model.SendProgressError("building models", fmt.Sprintf("unable to parse modified document: %s", err.Error()), errorChan)
errors = append(errors, err)
changeErrors = append(changeErrors, err)
}

if oldDoc != nil && newDoc != nil {
changes, errs := libopenapi.CompareDocuments(oldDoc, newDoc)

if errs != nil {
for a := range errs {
model.SendProgressError("building models", fmt.Sprintf("Error thrown when comparing: %s", errs[a].Error()), errorChan)
}
errors = append(errors, errs...)

model.SendProgressError("building models", fmt.Sprintf("Error thrown when comparing: %s", errors.Join(errs...)), errorChan)
changeErrors = append(changeErrors, errs...)
}
commitHistory[c].Changes = changes
} else {
Expand All @@ -192,7 +192,7 @@ func BuildCommitChangelog(commitHistory []*model.Commit,
for i, j := 0, len(cleaned)-1; i < j; i, j = i+1, j-1 {
cleaned[i], cleaned[j] = cleaned[j], cleaned[i]
}
return cleaned, errors
return cleaned, changeErrors
}

func ExtractPathAndFile(location string) (string, string) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/pb33f/openapi-changes

go 1.18
go 1.20

require (
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
Expand Down

0 comments on commit 8bb3328

Please sign in to comment.