From e062e02f9816ae14528e84220e7ea6ddd49a4a79 Mon Sep 17 00:00:00 2001 From: Andrey Piterkin Date: Mon, 9 Dec 2024 20:38:16 -0500 Subject: [PATCH] fix: wrap kinesis get records error in ScanShard instead of printing error message * wrap get records error using %w fmt code * add unit test for kinesis get records using errors.Is --- consumer.go | 2 +- consumer_test.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/consumer.go b/consumer.go index 74b59bbc..0bdc9a2f 100644 --- a/consumer.go +++ b/consumer.go @@ -192,7 +192,7 @@ func (c *Consumer) ScanShard(ctx context.Context, shardID string, fn ScanFunc) e c.logger.Log("[CONSUMER] get records error:", err.Error()) if !isRetriableError(err) { - return fmt.Errorf("get records error: %v", err.Error()) + return fmt.Errorf("get records error: %w", err) } shardIterator, err = c.getShardIterator(ctx, c.streamName, shardID, lastSeqNum) diff --git a/consumer_test.go b/consumer_test.go index d14b11ea..8391b900 100644 --- a/consumer_test.go +++ b/consumer_test.go @@ -396,6 +396,7 @@ func TestScanShard_ShardIsClosed_WithShardClosedHandler(t *testing.T) { } func TestScanShard_GetRecordsError(t *testing.T) { + getRecordsError := &types.InvalidArgumentException{Message: aws.String("aws error message")} var client = &kinesisClientMock{ getShardIteratorMock: func(ctx context.Context, params *kinesis.GetShardIteratorInput, optFns ...func(*kinesis.Options)) (*kinesis.GetShardIteratorOutput, error) { return &kinesis.GetShardIteratorOutput{ @@ -406,8 +407,7 @@ func TestScanShard_GetRecordsError(t *testing.T) { return &kinesis.GetRecordsOutput{ NextShardIterator: nil, Records: nil, - }, - &types.InvalidArgumentException{Message: aws.String("aws error message")} + }, getRecordsError }, } @@ -424,6 +424,10 @@ func TestScanShard_GetRecordsError(t *testing.T) { if err.Error() != "get records error: InvalidArgumentException: aws error message" { t.Fatalf("unexpected error: %v", err) } + + if !errors.Is(err, getRecordsError) { + t.Fatalf("unexpected error: %v", err) + } } type kinesisClientMock struct {