Skip to content

Commit

Permalink
Merge pull request mDialog#6 from damienlevin/master
Browse files Browse the repository at this point in the history
Added BrandoException
  • Loading branch information
chrisdinn committed Jun 19, 2013
2 parents 1a06654 + ac4cd4a commit 1675f1d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ Status replies are returned as case objects, such as `Pong` and `Ok`.

// Response: Some(Ok)

Error replies are returned as `Failure`

brando ! Request("EXPIRE", "1", "key")
// Response: Failure(brando.BrandoException: ERR value is not an integer or out of range)

Integer replies are returned as `Option[Int]`.

brando ! Request("SADD", "some-set", "one", "two")
Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/Brando.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import annotation.tailrec

import ExecutionContext.Implicits.global

private case class BrandoException(message: String) extends Exception(message) {
override lazy val toString = "%s: %s\n".format(getClass.getName, message)
}
private case class Connect(address: InetSocketAddress)
private case class CommandAck(sender: ActorRef) extends Tcp.Event
private object StartProcess
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/ReplyParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private[brando] trait ReplyParser {
buffer.take(length) match {
case ErrorReply(reply)
val remainder = buffer.drop(length)
Success(Some(Status.Failure(new Exception(reply.utf8String))), remainder)
Success(Some(Status.Failure(new BrandoException(reply.utf8String))), remainder)
case x
Failure(buffer)
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/scala/BrandoTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,15 @@ class BrandoTest extends TestKit(ActorSystem("BrandoTest")) with FunSpec

expectMsgPF(5.seconds) {
case Status.Failure(e)
assert(e.isInstanceOf[BrandoException])
assert(e.getMessage === "ERR wrong number of arguments for 'set' command")
}

brando ! Request("EXPIRE", "1", "key")

expectMsgPF(5.seconds) {
case Status.Failure(e)
assert(e.isInstanceOf[BrandoException])
assert(e.getMessage === "ERR value is not an integer or out of range")
}
}
Expand Down

0 comments on commit 1675f1d

Please sign in to comment.