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

Exceptions seem to be ignored by loggers #97

Open
zainab-ali opened this issue Nov 7, 2024 · 1 comment
Open

Exceptions seem to be ignored by loggers #97

zainab-ali opened this issue Nov 7, 2024 · 1 comment

Comments

@zainab-ali
Copy link
Contributor

This issue was copied over from: disneystreaming/weaver-test#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
Copy link
Contributor Author

This comment was copied over from: disneystreaming/weaver-test#639 (comment)
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.

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

1 participant