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

Do Not Filter Traces In ZIO Name Space #7637

Merged
merged 1 commit into from
Dec 28, 2022
Merged

Do Not Filter Traces In ZIO Name Space #7637

merged 1 commit into from
Dec 28, 2022

Conversation

adamgfraser
Copy link
Contributor

Resolves #7636.

[info] timestamp=2022-12-15T14:39:26.301869Z level=ERROR thread=#zio-fiber-0 message="" cause="Exception in thread "zio-fiber-4" java.lang.RuntimeException: bad
[info]  at Test$.badFunction(Example.scala:6)
[info]  at Test$.$anonfun$run$2(Example.scala:11)
[info]  at zio.ZIO.$anonfun$map$1(ZIO.scala:960)
[info]  at <empty>.Test.run(Example.scala:10)"

@vigoo
Copy link
Contributor

vigoo commented Dec 15, 2022

This will make developing ZIO ecosystem libraries much more pleasant :)

@jdegoes
Copy link
Member

jdegoes commented Dec 28, 2022

The problem seems to be that if a defect occurs directly inside a for comprehension as a val assignment, then the last known trace occurs on a preceding line of the for comprehension, which is incorrect. Basically, "defects between flatMap".

Is that correct assessment?

@adamgfraser
Copy link
Contributor Author

I don't think that is correct.

When an exception is thrown we already take the Throwable stack trace and combine it with the ZIO Trace, which is important independent of this if a ZIO workflow wraps a user defined function that calls several other functions one of which eventually throws an exception.

So for example this code generates the following stack trace:

image

[info] timestamp=2022-12-28T15:01:09.224126Z level=ERROR thread=#zio-fiber-0 message="" cause="Exception in thread "zio-fiber-4" java.lang.RuntimeException: bad
[info]  at Test$.badFunction(Example.scala:6)
[info]  at Test$.$anonfun$run$2(Example.scala:11)
[info]  at <empty>.Test.run(Example.scala:10)"

This is I think exactly what we want. The exception is thrown on line 6 in badFunction, badFunction was called in line 11 of the for comprehension, and that was called in the flatMap on line 10 of the for comprehension.

The issue here is that we currently have this logic to filter out traces in the ZIO name space. So if I take the same example as above and change import zio._ to package zio the trace will be filtered out. This PR resolves that by going back to only filtering out traces from the runtime itself.

@jdegoes jdegoes merged commit ecd877d into zio:series/2.x Dec 28, 2022
@jdegoes
Copy link
Member

jdegoes commented Dec 28, 2022

All right, makes sense, thank you!

@adamgfraser adamgfraser deleted the 7636 branch December 28, 2022 16:09
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.

Misleading stack trace in case of exception in a mapped pure function
3 participants