Skip to content

Commit ba6f442

Browse files
mhmtszrAchille
andauthored
Update WriteErrors error message (#964)
* 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>
1 parent ab4d8da commit ba6f442

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

error.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,6 @@ func makeError(code int16, message string) error {
684684
// // handle other errors
685685
// ...
686686
// }
687-
//
688687
type WriteErrors []error
689688

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

703702
func (err WriteErrors) Error() string {
704-
return fmt.Sprintf("kafka write errors (%d/%d)", err.Count(), len(err))
703+
errCount := err.Count()
704+
errors := make([]string, 0, errCount)
705+
for _, writeError := range err {
706+
if writeError == nil {
707+
continue
708+
}
709+
errors = append(errors, writeError.Error())
710+
}
711+
return fmt.Sprintf("Kafka write errors (%d/%d), errors: %v", errCount, len(err), errors)
705712
}

0 commit comments

Comments
 (0)