Skip to content

Commit

Permalink
Merge pull request #501 from nox213/scala2
Browse files Browse the repository at this point in the history
Enrich error message when derivation fails.
  • Loading branch information
adamw authored Dec 12, 2023
2 parents 3d99434 + e036de4 commit 7a26c66
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/src/main/scala/magnolia1/magnolia.scala
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,17 @@ object Magnolia {
val term = TermName(termName)
val classWithTerm = c.prefix.tree.tpe.baseClasses
.find(cls => cls.asType.toType.decl(term) != NoSymbol)
.getOrElse(error(s"the method `$termName` must be defined on the derivation $prefixObject to derive typeclasses for $category"))
.getOrElse {
val searchType = stack.top.map(_.searchType.toString)
val additionalInfo = searchType match {
case Some(tpe) => s"unable to derive $tpe -- "
case None => ""
}

error(
s"${additionalInfo}the method `$termName` must be defined on the derivation $prefixObject to derive typeclasses for $category"
)
}

classWithTerm.asType.toType.decl(term).asTerm.asMethod.paramLists.head
}
Expand Down

0 comments on commit 7a26c66

Please sign in to comment.