Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap Throwables Returned from Queues #65

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object RedisConnection{
chunk.traverse(resp => Deferred[F, Either[Throwable, Resp]].map(d => (d, ({(e: Either[Throwable, Resp]) => d.complete(e).void}, resp)))).flatMap{ c =>
queue.offer(c.map(_._2)) >> {
val x: F[Chunk[Either[Throwable, Resp]]] = c.traverse{ case (d, _) => d.get }
val y: F[Chunk[Resp]] = x.flatMap(_.sequence.liftTo[F])
val y: F[Chunk[Resp]] = x.flatMap(_.sequence.liftTo[F].adaptError{case e => RedisError.QueuedExceptionError(e)})
y
}
}
Expand Down Expand Up @@ -69,7 +69,7 @@ object RedisConnection{
val chunk = Chunk.seq(inputs.toList.map(Resp.renderRequest))
chunk.traverse(resp => Deferred[F, Either[Throwable, Resp]].map(d => (d, ({(e: Either[Throwable, Resp]) => d.complete(e).void}, key, None, 0, resp)))).flatMap{ c =>
queue.offer(c.map(_._2)) >> {
c.traverse(_._1.get).flatMap(_.sequence.liftTo[F])
c.traverse(_._1.get).flatMap(_.sequence.liftTo[F].adaptError{case e => RedisError.QueuedExceptionError(e)})
}
}
}
Expand Down Expand Up @@ -311,13 +311,13 @@ object RedisConnection{
}
case l@Left(_) => l.rightCast[Chunk[Resp]].pure[F]
}.flatMap{
case Right(n) =>
case Right(n) =>
n.zipWithIndex.traverse_{
case (ref, i) =>
val (toSet, _) = chunk(i)
toSet(Either.right(ref))
}
case e@Left(_) =>
case e@Left(_) =>
chunk.traverse_{ case (deff, _) => deff(e.asInstanceOf[Either[Throwable, Resp]])}
})
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ object RedisError {
final case class Generic(message: String) extends RedisError{
val cause: Option[Throwable] = None
}

final case class QueuedExceptionError(baseCase: Throwable) extends RedisError {
override val message: String = s"Error encountered in queue: ${baseCase.getMessage()}"
override val cause: Option[Throwable] = Some(baseCase)
}
}