Skip to content

Commit

Permalink
Update WriteErrors error message (segmentio#964)
Browse files Browse the repository at this point in the history
* Update WriteErrors error message

* Update error.go

* Handle error nil case

* Update error message for write errors

* preallocate the errors slice

Co-authored-by: Achille <achille@segment.com>
  • Loading branch information
mhmtszr and Achille committed Sep 2, 2022
1 parent ab4d8da commit ba6f442
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,6 @@ func makeError(code int16, message string) error {
// // handle other errors
// ...
// }
//
type WriteErrors []error

// Count counts the number of non-nil errors in err.
Expand All @@ -701,5 +700,13 @@ func (err WriteErrors) Count() int {
}

func (err WriteErrors) Error() string {
return fmt.Sprintf("kafka write errors (%d/%d)", err.Count(), len(err))
errCount := err.Count()
errors := make([]string, 0, errCount)
for _, writeError := range err {
if writeError == nil {
continue
}
errors = append(errors, writeError.Error())
}
return fmt.Sprintf("Kafka write errors (%d/%d), errors: %v", errCount, len(err), errors)
}

0 comments on commit ba6f442

Please sign in to comment.