-
Notifications
You must be signed in to change notification settings - Fork 82
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
Every exceptions logged as FiberFailure #891
Comments
Hello @leejaeseung, It is like you mentioning, every exception is wrapped with This was made for one reason, to have proper stack traces ZIO together with java code package zio.logging.example
object Test {
def foo(): Unit =
bar()
private def bar(): Unit =
doe()
private def doe(): Unit =
throw new RuntimeException("test doe")
}
package zio.logging.example
import zio._
import zio.logging.backend.SLF4J
object Example2 extends ZIOAppDefault {
override val bootstrap: ZLayer[ZIOAppArgs, Any, Environment] =
Runtime.removeDefaultLoggers >>> SLF4J.slf4j
def foo: ZIO[Any, Throwable, Unit] =
for {
_ <- bar
} yield ()
def bar: ZIO[Any, Throwable, Unit] =
for {
_ <- baz
} yield ()
def baz: ZIO[Any, Throwable, Unit] =
ZIO.attempt(Test.foo())
val run: ZIO[Any, Throwable, Unit] =
foo.tapErrorCause(cause => ZIO.logErrorCause("ERROR", cause))
}
where log output (with current zio-logging version) will be
with val causeToThrowableDefault: Cause[Any] => Option[Throwable] = cause =>
if (cause.isEmpty) {
None
} else {
val maybeThrowable = (cause.failures.collect { case t: Throwable => t } ++ cause.defects).headOption
maybeThrowable.orElse(Some(FiberFailure(cause)))
} will be
I agree that it is not best to have everything wrapped like Ideas for improvements are welcome. Thank you very much. |
@justcoon Thank you for answer :) I have searched codes and understood that ZIO Cause’s stack traces are missed if just extracting throwable. I agree with showing Cause’s traces is important, too. But I still worried about the fixed root exception. (it changes my alert message) So, how about using suppressed exception? Like this : // A custom Exception To save Cause's stack traces. (copy of FiberFailure)
final case class SuppressedCauseException(cause: Cause[Any]) extends Throwable(null, null, true, false) {
override def getMessage: String = cause.unified.headOption.fold("<unknown>")(_.message)
override def getStackTrace(): Array[StackTraceElement] = {
cause.unified.headOption.fold[Chunk[StackTraceElement]](Chunk.empty)(_.trace).toArray
}
}
// just simple implements. (please ignore details - like unsafe .get)
val causeToThrowableDefault: Cause[Any] => Option[Throwable] = cause =>
if (cause.isEmpty) {
None
} else {
val maybeThrowable = (cause.failures.collect { case t: Throwable => t } ++ cause.defects).headOption
val failure = SuppressedCauseException(cause)
if(!maybeThrowable.get.getSuppressed.contains(failure)) {
maybeThrowable.get.addSuppressed(failure)
}
Some(maybeThrowable.get)
} And it’s traces look like this
it may seems a little weird. But i think it may be one of the possible options to maintain the root exception. |
related with #811
Hi, I recently upgraded this library version from 2.1.12 to 2.3.1.
After upgrade, every error log’s root exception was changed to FiberFailure.
(And so our every error alert turn to FiberFailure - using sentry)
It’s because this code (v2.12.2)
changed to (v2.3.1)
FiberFailure’s desciption :
I think some failures in cause are not case of FiberFailure. (it’s recoverable)
So i think the extracting cause’s failures code should put into where cause is not empty.
Like this :
If I missed something, please correct me. thanks :)
The text was updated successfully, but these errors were encountered: