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

assert fail throws Boxed Error #275

Closed
aleagnelli opened this issue Dec 12, 2020 · 4 comments
Closed

assert fail throws Boxed Error #275

aleagnelli opened this issue Dec 12, 2020 · 4 comments

Comments

@aleagnelli
Copy link

When this code is executed I get a Boxed Error, which can be confusing

class Test extends munit.FunSuite {

  case class Inner(value: Double)

  case class Outer(data: Seq[Inner])

  test("exist issue") {
    val values = Array(
      Outer(Seq(Inner(1), Inner(2), Inner(10))),
      Outer(Seq(Inner(1), Inner(2), Inner(10))),
      Outer(Seq(Inner(1), Inner(2), Inner(10)))
    )
    assert(values.exists(outer => outer.data.exists(inner => inner.value > 90)))
  }

}

Result:

java.util.concurrent.ExecutionException: Boxed Error

    at scala.concurrent.impl.Promise$.resolver(Promise.scala:87)
    at scala.concurrent.impl.Promise$.scala$concurrent$impl$Promise$$resolveTry(Promise.scala:79)
    at scala.concurrent.impl.Promise$KeptPromise$.apply(Promise.scala:406)
    at scala.concurrent.Promise$.fromTry(Promise.scala:142)
    at scala.concurrent.Future$.fromTry(Future.scala:640)
    at munit.ValueTransforms.munitValueTransform(ValueTransforms.scala:37)
    at munit.ValueTransforms.munitValueTransform$(ValueTransforms.scala:22)
    at munit.FunSuite.munitValueTransform(FunSuite.scala:11)
    at munit.FunSuite.$anonfun$test$1(FunSuite.scala:37)
    at munit.MUnitRunner.$anonfun$runTestBody$1(MUnitRunner.scala:290)
Caused by: munit.FailException: /home/ale/workspace/munit_issue/src/test/scala/Test.scala:13 assertion failed
12:    )
13:    assert(values.exists(outer => outer.data.exists(inner => inner.value > 90)))
14:  }
    at munit.FunSuite.assert(FunSuite.scala:11)
    at Test.$anonfun$new$1(Test.scala:13)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)

Expected:

munit.FailException: /home/ale/workspace/munit_issue/src/test/scala/Test.scala:13 assertion failed
12:    )
13:    assert(values.exists(outer => outer.data.exists(inner => inner.value > 90)))
14:  }

    at munit.FunSuite.assert(FunSuite.scala:11)
    at Test.$anonfun$new$1(Test.scala:13)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)

If the assertion return true everything works as expected
munit version: 0.7.19
scala version: 2.11.12, 2.12.12

scala version 2.13.4 works as expected

@aleagnelli aleagnelli changed the title assert fails throws Boxed Error assert fail throws Boxed Error Dec 12, 2020
@gabro
Copy link
Member

gabro commented Dec 13, 2020

Hi @alexagnelli, thanks for reporting. This is due to how Future handles subclasses of java.lang.Error:

ExecutionException - stored when the computation fails due to an unhandled InterruptedException, Error or a scala.util.control.ControlThrowable. In this case the ExecutionException has the unhandled exception as its cause. The rationale behind this is to prevent propagation of critical and control-flow related exceptions normally not handled by the client code and at the same time inform the client in which future the computation failed.

from https://docs.scala-lang.org/overviews/core/futures.html

Ultimately this is caused by MUnit's exceptions extending AssertionError, which in turn extends Error.

I've tried digging a bit into this, but I couldn't spot an easy way to get rid of the intermediate ExecutionException when reporting the error. I'm open to suggestions if somebody more expert than me on the matter wants to chime in.

@aleagnelli
Copy link
Author

aleagnelli commented Dec 13, 2020

Hi @gabro, thank you for digging up so quickly.
There is still one thing that is not clear to me: in scala 2.13.4 the Error is handled as expected, but I didn't find any change in Future behavior's, any idea what is happening different?

The only thing I found is:

Futures were internally redesigned, with these goals:

provide expected behavior under a broader set of failure conditions

https://github.com/scala/scala/releases/tag/v2.13.0

@gabro
Copy link
Member

gabro commented Dec 14, 2020

@alexagnelli the only thing related there is the handling of InterruptedException (which is similar in fashion) by the ExecutionContext. I suspect something similar has been done for Error but I couldn't pinpoint the specific diff after a quick look

@olafurpg
Copy link
Member

Thank you for reporting! I actually had a pending fix for this issue in 265769e (#225) but didn't merge the PR #225. I opened #277 with a cherry-pick of that commit

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

No branches or pull requests

3 participants