diff --git a/src/main/scala/redis/Operation.scala b/src/main/scala/redis/Operation.scala index 7660e2a4..8a5662f2 100644 --- a/src/main/scala/redis/Operation.scala +++ b/src/main/scala/redis/Operation.scala @@ -4,6 +4,8 @@ import scala.concurrent.Promise import redis.protocol.{DecodeResult, RedisReply} import akka.util.ByteString +import scala.util.Try + case class Operation[RedisReplyT <: RedisReply, T](redisCommand: RedisCommand[RedisReplyT, T], promise: Promise[T]) { def decodeRedisReplyThenComplete(bs: ByteString): DecodeResult[Unit] = { val r = redisCommand.decodeRedisReply.apply(bs) @@ -13,13 +15,13 @@ case class Operation[RedisReplyT <: RedisReply, T](redisCommand: RedisCommand[Re } def completeSuccess(redisReply: RedisReplyT): Promise[T] = { - val v = redisCommand.decodeReply(redisReply) - promise.success(v) + val v = Try(redisCommand.decodeReply(redisReply)) + promise.complete(v) } def tryCompleteSuccess(redisReply: RedisReply) = { - val v = redisCommand.decodeReply(redisReply.asInstanceOf[RedisReplyT]) - promise.trySuccess(v) + val v = Try(redisCommand.decodeReply(redisReply.asInstanceOf[RedisReplyT])) + promise.tryComplete(v) } def completeSuccessValue(value: T) = promise.success(value) diff --git a/src/test/scala/redis/commands/StringsSpec.scala b/src/test/scala/redis/commands/StringsSpec.scala index abcd5996..c4fecb81 100644 --- a/src/test/scala/redis/commands/StringsSpec.scala +++ b/src/test/scala/redis/commands/StringsSpec.scala @@ -1,6 +1,7 @@ package redis.commands import redis._ + import scala.concurrent.{Await, Future} import akka.util.ByteString import redis.actors.ReplyErrorException @@ -117,6 +118,13 @@ class StringsSpec extends RedisStandaloneServer { Await.result(r, timeOut) mustEqual Some(dumbObject) } + "GET with deserialization failure" in { + val r = redis.set("getDumbKey", "value").flatMap(_ => { + redis.get[Double]("getDumbKey") + }) + Await.result(r, timeOut) must throwA[NumberFormatException] + } + "GETBIT" in { val r = redis.getbit("getbitKeyNonexisting", 0) val r2 = redis.set("getbitKey", "Hello").flatMap(_ => {