kafka-go
kafka-go copied to clipboard
WriteErrors don't return the actual error
Describe the bug
We can't see the actual errors of our batch write request. It creates new error and this error does not contain any information about the error
return fmt.Sprintf("kafka write errors (%d/%d)", err.Count(), len(err)). We need to see the detail of the error.
Kafka Version
- github.com/segmentio/kafka-go v0.4.29
To Reproduce
Get any error while processing the batch write request.
Expected Behavior
We need to see the detail of the error.
Observed Behavior
We can't see the actual error we only see the count of the errors.
Hi @mhmtszr,
See https://pkg.go.dev/github.com/segmentio/kafka-go?utm_source=godoc#WriteErrors for an example of inspecting individual errors within a WriteErrors.
Hopefully that helps!
Thanks!
@rhansen2 hi,
Thanks this solved our problem but I think there should be a cleaner way, we shouldn't have to do this conversion what do you think?
What did you have in mind?
Instead of this
func (err WriteErrors) Error() string {
return fmt.Sprintf("kafka write errors (%d/%d)", err.Count(), len(err))
}
We may have error message like this
func (err WriteErrors) Error() string {
var sb strings.Builder
for i, writeError := range err {
sb.WriteString(fmt.Sprintf("%d: %s ", i, writeError.Error()))
}
return fmt.Sprintf("kafka write errors (%d/%d), errors: ", err.Count(), len(err), sb.String())
}
In this way we can log the producer errors without doing any convertion.
I think that sounds good @mhmtszr, would you be able to submit a pull request?
@rhansen2 https://github.com/segmentio/kafka-go/pull/964 I created a pull request and will wait for the reviews thanks.