typelevel / weaver-test

A test framework that runs everything in parallel.
https://typelevel.org/weaver-test/
Other
46 stars 8 forks source link

Exceptions seem to be ignored by loggers #97

Open zainab-ali opened 2 weeks ago

zainab-ali commented 2 weeks ago

This issue was copied over from: https://github.com/disneystreaming/weaver-test/issues/639 It was opened by: kubukoz


It appears that log.error(msg, cause = someThrowable) doesn't actually use the throwable to present a meaningful message: neither the throwable's message nor the stack trace appear in logs by default.

Example (you might as well construct an exception yourself, but I relied on a good old NPE here):

import weaver.SimpleIOSuite

import scala.util.Try

object MyTest extends SimpleIOSuite {

  test("null pointer") { (_, log) =>
    val e =
      try {
        (null: String).length()
        sys.error("can't get here")
      } catch {
        case e: NullPointerException => e
      }

    log
      .error
      .apply("an error", cause = e)
      .as(assert.eql(false, true))
  }
}

Actual output on sbt test:

sbt:root> test
[info] compiling 1 Scala source to /Users/kubukoz/projects/demos/target/scala-2.13/test-classes ...
[info] MyTest
[info] - null pointer 12ms
[info] *************FAILURES**************
[info] MyTest
[error] - null pointer 12ms
[error]   Values not equal: (src/test/scala/MyTest.scala:19)
[error] 
[error]   [false]  |  [true]
[error] 
[error]     [ERROR] 14:06:42 [MyTest.scala:18] an error
[error] 
[error] Failed: Total 1, Failed 1, Errors 0, Passed 0
[error] Failed tests:
[error]         MyTest
[error] (Test / test) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 1 s, completed Feb 27, 2023, 2:06:42 PM

I'd expect to see the exception message and stack trace somewhere in the logs.

Versions affected: tried 0.8.1 and a local snapshot of the latest main, 0.8.1+35-b03d8212-SNAPSHOT.

zainab-ali commented 2 weeks ago

This comment was copied over from: https://github.com/disneystreaming/weaver-test/issues/639#issuecomment-1458792156 It was written by: henryxparker


I have run into this issue as well

Edit: I have made a PR for a quick&dirty change that would fix this. I personally think this is a critical bug. It has made me reluctant to use weaver when it would otherwise be a great fit because I can't be sure that I will be able to see what exceptions caused my code to fail unless I rethrow them. And rethrowing every exception is not an option.