From 2d5bb4b7bc4c6ec48df39b3c9ffc3b87a3524ae4 Mon Sep 17 00:00:00 2001 From: Nathan <148575555+nathan-artie@users.noreply.github.com> Date: Fri, 26 Jan 2024 16:58:14 -0800 Subject: [PATCH] Move Fatal call out of DynamoDB Load (#53) --- main.go | 5 ++++- sources/dynamodb/dynamodb.go | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 6d8f4058..243cd247 100644 --- a/main.go +++ b/main.go @@ -75,7 +75,10 @@ func main() { switch cfg.Source { case "", config.SourceDynamo: - ddb := dynamodb.Load(*cfg, statsD, _kafka) + ddb, err := dynamodb.Load(*cfg, statsD, _kafka) + if err != nil { + logger.Fatal("Failed to load dynamodb", slog.Any("err", err)) + } if err = ddb.Validate(); err != nil { logger.Fatal("Failed to validate dynamodb", slog.Any("err", err)) } diff --git a/sources/dynamodb/dynamodb.go b/sources/dynamodb/dynamodb.go index f5b162a8..e318dd9d 100644 --- a/sources/dynamodb/dynamodb.go +++ b/sources/dynamodb/dynamodb.go @@ -42,14 +42,13 @@ type Store struct { const jitterSleepBaseMs = 50 const shardScannerInterval = 5 * time.Minute -func Load(cfg config.Settings, statsD *mtr.Client, writer *kafka.Writer) *Store { +func Load(cfg config.Settings, statsD *mtr.Client, writer *kafka.Writer) (*Store, error) { sess, err := session.NewSession(&aws.Config{ Region: ptr.ToString(cfg.DynamoDB.AwsRegion), Credentials: credentials.NewStaticCredentials(cfg.DynamoDB.AwsAccessKeyID, cfg.DynamoDB.AwsSecretAccessKey, ""), }) - if err != nil { - logger.Fatal("Failed to create session", slog.Any("err", err)) + return nil, fmt.Errorf("failed to create session, err: %w", err) } store := &Store{ @@ -73,7 +72,7 @@ func Load(cfg config.Settings, statsD *mtr.Client, writer *kafka.Writer) *Store store.shardChan = make(chan *dynamodbstreams.Shard) } - return store + return store, nil } func (s *Store) Validate() error {