From 8d9a555a0778cd75094e1ad7cf1ba08bc124a649 Mon Sep 17 00:00:00 2001 From: semenodm Date: Sat, 18 Apr 2020 12:36:12 -0400 Subject: [PATCH] Do not fail on unsupported dynamo evt (#273) * introduce Unsupported event type for the (NEW_IMAGE, REMOVE) pair * fix test * add reason description into unsupported event Co-authored-by: d.semenov --- .../main/scala/fs2/aws/dynamodb/parsers/BeforeAfter.scala | 1 + .../src/main/scala/fs2/aws/dynamodb/parsers/package.scala | 2 ++ .../fs2/aws/dynamodb/parsers/DynamoEventParserSpec.scala | 7 +++---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/fs2-aws-dynamodb/src/main/scala/fs2/aws/dynamodb/parsers/BeforeAfter.scala b/fs2-aws-dynamodb/src/main/scala/fs2/aws/dynamodb/parsers/BeforeAfter.scala index ba082536..0021f62c 100644 --- a/fs2-aws-dynamodb/src/main/scala/fs2/aws/dynamodb/parsers/BeforeAfter.scala +++ b/fs2-aws-dynamodb/src/main/scala/fs2/aws/dynamodb/parsers/BeforeAfter.scala @@ -5,3 +5,4 @@ sealed trait DynamoDBBeforeAfter[T] case class Insert[T](after: T) extends DynamoDBBeforeAfter[T] case class Update[T](before: T, after: T) extends DynamoDBBeforeAfter[T] case class Delete[T](before: T) extends DynamoDBBeforeAfter[T] +case class Unsupported[T](reason: String) extends DynamoDBBeforeAfter[T] diff --git a/fs2-aws-dynamodb/src/main/scala/fs2/aws/dynamodb/parsers/package.scala b/fs2-aws-dynamodb/src/main/scala/fs2/aws/dynamodb/parsers/package.scala index 881159a9..0bb7430d 100644 --- a/fs2-aws-dynamodb/src/main/scala/fs2/aws/dynamodb/parsers/package.scala +++ b/fs2-aws-dynamodb/src/main/scala/fs2/aws/dynamodb/parsers/package.scala @@ -28,6 +28,8 @@ package object parsers { case ("OLD_IMAGE" | "NEW_AND_OLD_IMAGES", "REMOVE") => parseDynamoRecord(record.getInternalObject.getDynamodb.getOldImage) .map(after => Delete(after)) + case ("NEW_IMAGE", "REMOVE") => + Sync[F].pure(Unsupported("NEW_IMAGE is not supported with REMOVE")) case (viewType, operationType) => Sync[F].raiseError(new RuntimeException(s"$viewType is not supported with $operationType")) } diff --git a/fs2-aws-dynamodb/src/test/scala/fs2/aws/dynamodb/parsers/DynamoEventParserSpec.scala b/fs2-aws-dynamodb/src/test/scala/fs2/aws/dynamodb/parsers/DynamoEventParserSpec.scala index 31fde6a5..d328cd9f 100644 --- a/fs2-aws-dynamodb/src/test/scala/fs2/aws/dynamodb/parsers/DynamoEventParserSpec.scala +++ b/fs2-aws-dynamodb/src/test/scala/fs2/aws/dynamodb/parsers/DynamoEventParserSpec.scala @@ -90,10 +90,9 @@ class DynamoEventParserSpec extends AnyWordSpec with Matchers { val r = new Record() r.setEventName(OperationType.REMOVE) r.withDynamodb(sr) - val thrown = intercept[Exception] { - parseDynamoEvent[IO, Json](new RecordAdapter(r)).unsafeRunSync() - } - thrown.getMessage should be("NEW_IMAGE is not supported with REMOVE") + parseDynamoEvent[IO, Json](new RecordAdapter(r)).unsafeRunSync() should be( + Unsupported("NEW_IMAGE is not supported with REMOVE") + ) } } }