kafka-go icon indicating copy to clipboard operation
kafka-go copied to clipboard

WriteErrors don't return the actual error

Open mhmtszr opened this issue 3 years ago • 6 comments

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.

mhmtszr avatar Jul 27 '22 13:07 mhmtszr

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 avatar Jul 27 '22 19:07 rhansen2

@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?

mhmtszr avatar Jul 28 '22 05:07 mhmtszr

What did you have in mind?

rhansen2 avatar Jul 29 '22 02:07 rhansen2

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.

mhmtszr avatar Jul 29 '22 05:07 mhmtszr

I think that sounds good @mhmtszr, would you be able to submit a pull request?

rhansen2 avatar Aug 03 '22 16:08 rhansen2

@rhansen2 https://github.com/segmentio/kafka-go/pull/964 I created a pull request and will wait for the reviews thanks.

mhmtszr avatar Aug 03 '22 16:08 mhmtszr