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

Improve query probing error message #845

Merged
merged 1 commit into from
Jul 19, 2017
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 @@ -21,15 +21,20 @@ object ProbeStatement {

def resolveContext(tpe: Type) =
tpe match {
case tpe if (tpe <:< c.weakTypeOf[QueryProbing]) =>
case tpe if tpe <:< c.weakTypeOf[QueryProbing] =>
LoadObject[Context[Idiom, NamingStrategy]](c)(tpe) match {
case Success(context) =>
Some(context)
case Failure(ex) =>
c.error(s"Can't load the context of type '$tpe' for compile-time query probing. Reason: '$ex'")
c.error(
s"Can't load the context of type '$tpe' for a compile-time query probing. " +
s"Make sure that context creation happens in a separate compilation unit. " +
s"For more information please refer to the documentation http://getquill.io/#quotation-query-probing. " +
s"Reason: '$ex'"
)
None
}
case other =>
case _ =>
None
}

Expand All @@ -38,7 +43,7 @@ object ProbeStatement {
cache
.getOrElseUpdate(tpe, resolveContext(tpe), 30.seconds)
.map(_.probe(statement))
.map {
.foreach {
case Success(_) =>
case Failure(ex) =>
c.error(s"Query probing failed. Reason: '$ex'")
Expand Down
3 changes: 2 additions & 1 deletion quill-core/src/test/scala/io/getquill/QueryProbingSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package io.getquill
class QueryProbingSpec extends Spec {

"fails if the context can't be resolved at compile time" in {
object c extends MirrorContext[MirrorIdiom, Literal] with QueryProbing
object c extends MirrorContext[MirrorIdiom, Literal] with TestEntities with QueryProbing
import c._
"c.run(qr1)" mustNot compile
}

Expand Down