Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Kafka] Update error assertion for MessageTooLargeError #396

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/kafkalib/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import (
)

func isExceedMaxMessageBytesErr(err error) bool {
return err != nil && errors.Is(err, kafka.MessageSizeTooLarge)
var e kafka.MessageTooLargeError
if err != nil && errors.As(err, &e) {
return true
}

return false
}

// isRetryableError - returns true if the error is retryable
Expand Down
2 changes: 1 addition & 1 deletion lib/kafkalib/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestIsExceedMaxMessageBytesErr(t *testing.T) {
expected: false,
},
{
err: kafka.MessageSizeTooLarge,
err: kafka.MessageTooLargeError{},
expected: true,
},
}
Expand Down
1 change: 1 addition & 0 deletions lib/kafkalib/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (b *BatchWriter) Write(ctx context.Context, rawMsgs []lib.RawMessage) error
break
}

fmt.Println("kafkaErr: ", kafkaErr, isExceedMaxMessageBytesErr(kafkaErr))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra print statement.

if isExceedMaxMessageBytesErr(kafkaErr) {
slog.Info("Skipping this batch since the message size exceeded the server max")
kafkaErr = nil
Expand Down