From 28a9fdff30302876396ea930fd3af74c1194e663 Mon Sep 17 00:00:00 2001 From: zaneli Date: Tue, 12 Dec 2017 20:13:54 +0900 Subject: [PATCH] Use `Messages.fail` instead of throwing exception directly --- .../src/main/scala/io/getquill/MysqlAsyncContext.scala | 3 ++- .../src/main/scala/io/getquill/PostgresAsyncContext.scala | 3 ++- quill-core/src/main/scala/io/getquill/context/Context.scala | 3 ++- quill-core/src/main/scala/io/getquill/monad/IOMonad.scala | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/quill-async-mysql/src/main/scala/io/getquill/MysqlAsyncContext.scala b/quill-async-mysql/src/main/scala/io/getquill/MysqlAsyncContext.scala index fe90476708..3ed282352a 100644 --- a/quill-async-mysql/src/main/scala/io/getquill/MysqlAsyncContext.scala +++ b/quill-async-mysql/src/main/scala/io/getquill/MysqlAsyncContext.scala @@ -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]) @@ -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.") } } } diff --git a/quill-async-postgres/src/main/scala/io/getquill/PostgresAsyncContext.scala b/quill-async-postgres/src/main/scala/io/getquill/PostgresAsyncContext.scala index 1220fd34e9..b2c46db436 100644 --- a/quill-async-postgres/src/main/scala/io/getquill/PostgresAsyncContext.scala +++ b/quill-async-postgres/src/main/scala/io/getquill/PostgresAsyncContext.scala @@ -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) @@ -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.") } } diff --git a/quill-core/src/main/scala/io/getquill/context/Context.scala b/quill-core/src/main/scala/io/getquill/context/Context.scala index ad118bbe82..c1045c1680 100644 --- a/quill-core/src/main/scala/io/getquill/context/Context.scala +++ b/quill-core/src/main/scala/io/getquill/context/Context.scala @@ -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 @@ -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") } } diff --git a/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala b/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala index 1f73f50e99..9ca40795ac 100644 --- a/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala +++ b/quill-core/src/main/scala/io/getquill/monad/IOMonad.scala @@ -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 @@ -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))