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

Add a cause to the munit Checker failure #1564

Merged

Conversation

brendanmaguire
Copy link
Contributor

  • Add an ErrorItems exception as the failure cause
  • This allows clients to inspect and filter failures on their underlying cause Items

* Add an `ErrorItems` exception as the failure cause
* This allows clients to inspect and filter failures on their underlying cause `Item`s
@jatcwang jatcwang self-requested a review October 12, 2021 10:54
@jatcwang
Copy link
Collaborator

Just for my own learning, @brendanmaguire can you briefly explain what "client" you're using that this is helpful? :)

@brendanmaguire
Copy link
Contributor Author

@jatcwang Sorry, client was probably the wrong word above 🙂 I am using this with the Big Query JDBC driver like so:

class QueriesItUtils extends munit.FunSuite with IOCheckerWithErrors {
  override val transactor: Transactor[IO] = TransactorUtils.transactor[IO]()

  test("my query should be valid")(checkQuery(sql.myQuery))

  private def checkQuery[A](query: Query0[A]) = ignoreNullableFieldErrors(check(query))

  // The BigQuery JDBC driver does not convey metadata about the nullability of the columns. By ignoring nullable errors
  // the type check tests can still be run and provide useful information about misaligned queries and schema
  private def ignoreNullableFieldErrors(checkResult: => Unit) =
    Try(checkResult).recover {
      case failException: munit.FailException =>
        failException.cause match {
          case ErrorItems(items) if onlyNullableFieldErrors(items) => ()
          case _                                                   => throw failException
        }
    }.get

  private def onlyNullableFieldErrors(items: List[AnalysisReport.Item]): Boolean =
    items
      .flatMap(_.error)
      .forall(_.lines.forall(_.startsWith(nullableFieldErrorString)))

  private val nullableFieldErrorString = "Reading a NULL value into"
}

Copy link
Collaborator

@jatcwang jatcwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that makes sense :)

@jatcwang jatcwang merged commit a2c0733 into typelevel:main Oct 12, 2021
@brendanmaguire brendanmaguire deleted the add-cause-to-munit-checker-failure branch October 13, 2021 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants