Skip to content

Commit

Permalink
Merge pull request #995 from zaneli/use-util-fail
Browse files Browse the repository at this point in the history
Use `Messages.fail` instead of throwing exception directly
  • Loading branch information
fwbrasil authored Dec 12, 2017
2 parents 0606e15 + 28a9fdf commit ca245c1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.github.mauricio.async.db.pool.PartitionedConnectionPool
import com.typesafe.config.Config
import io.getquill.context.async.{ AsyncContext, UUIDStringEncoding }
import io.getquill.util.LoadConfig
import io.getquill.util.Messages.fail
import com.github.mauricio.async.db.general.ArrayRowData

class MysqlAsyncContext[N <: NamingStrategy](naming: N, pool: PartitionedConnectionPool[MySQLConnection])
Expand All @@ -21,7 +22,7 @@ class MysqlAsyncContext[N <: NamingStrategy](naming: N, pool: PartitionedConnect
case r: MySQLQueryResult =>
returningExtractor(new ArrayRowData(0, Map.empty, Array(r.lastInsertId)))
case _ =>
throw new IllegalStateException("This is a bug. Cannot extract returning value.")
fail("This is a bug. Cannot extract returning value.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.github.mauricio.async.db.postgresql.PostgreSQLConnection
import com.typesafe.config.Config
import io.getquill.context.async.{ ArrayDecoders, ArrayEncoders, AsyncContext, UUIDObjectEncoding }
import io.getquill.util.LoadConfig
import io.getquill.util.Messages.fail

class PostgresAsyncContext[N <: NamingStrategy](naming: N, pool: PartitionedConnectionPool[PostgreSQLConnection])
extends AsyncContext(PostgresDialect, naming, pool)
Expand All @@ -22,7 +23,7 @@ class PostgresAsyncContext[N <: NamingStrategy](naming: N, pool: PartitionedConn
case Some(r) if r.nonEmpty =>
returningExtractor(r.head)
case _ =>
throw new IllegalStateException("This is a bug. Cannot extract returning value.")
fail("This is a bug. Cannot extract returning value.")
}
}

Expand Down
3 changes: 2 additions & 1 deletion quill-core/src/main/scala/io/getquill/context/Context.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.getquill.context
import scala.language.higherKinds
import scala.language.experimental.macros
import io.getquill.dsl.CoreDsl
import io.getquill.util.Messages.fail
import java.io.Closeable
import scala.util.Try
import io.getquill.NamingStrategy
Expand Down Expand Up @@ -43,6 +44,6 @@ trait Context[Idiom <: io.getquill.idiom.Idiom, Naming <: NamingStrategy]
protected def handleSingleResult[T](list: List[T]) =
list match {
case value :: Nil => value
case other => throw new IllegalStateException(s"Expected a single result but got $other")
case other => fail(s"Expected a single result but got $other")
}
}
3 changes: 2 additions & 1 deletion quill-core/src/main/scala/io/getquill/monad/IOMonad.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import scala.util.Failure
import scala.util.Success
import scala.util.Try
import io.getquill.context.Context
import io.getquill.util.Messages.fail

sealed trait Effect

Expand Down Expand Up @@ -47,7 +48,7 @@ trait IOMonad {
def zip[T, E1 <: Effect, S, E2 <: Effect](a: IO[T, E1], b: IO[S, E2]): IO[(T, S), E1 with E2] =
sequence(List(a, b)).map {
case a :: b :: Nil => (a.asInstanceOf[T], b.asInstanceOf[S])
case other => throw new IllegalStateException("Sequence returned less than two elements")
case _ => fail("Sequence returned less than two elements")
}

def failed[T](exception: Throwable): IO[T, Effect] = fromTry(Failure(exception))
Expand Down

0 comments on commit ca245c1

Please sign in to comment.