Skip to content

Conversation

dubinsky
Copy link
Contributor

@dubinsky dubinsky commented Aug 4, 2025

... and more propagating thereof.

On one end, it seems a shame to discard information that we have.

On the other end, receiver of the sbt.testing.Event - in my case, Gradle plugin for multi-backend Scala - has to provide a throwable to Gradle, which requires one to accompany a test failure, and if it is not propagated by the test framework, a fake throwable has to be concocted (ugh).

This change makes the ends meet ;)

@dubinsky dubinsky force-pushed the less-discarding-of-test-failure-throwables branch 2 times, most recently from e2cbfaf to c899da4 Compare August 4, 2025 17:10
@@ -45,7 +45,9 @@ object TestOutcome {
def cause: Option[Throwable] = result match {
case Result.Exception(cause, _) => Some(cause)
case Result.Failure(_, maybeCause, _) => maybeCause
case _ => None
case Result.Failures(failures) =>
failures.map(_.source).find(_.isDefined).flatten
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
failures.map(_.source).find(_.isDefined).flatten
failures.collectFirst {
case Result.Failure(_, Some(cause), _) => cause
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks!

@zainab-ali
Copy link
Contributor

Thanks!

My only concern (which doesn't need to be addressed) is that we're only taking the first failure and discarding others. If this ends up being a problem, we could define CompositeFailure exception that aggregates the causes.

... and more propagating thereof.

On one end, it seems a shame to discard information that we have.

On the other end, receiver of the `sbt.testing.Event` - in my case, [Gradle plugin for multi-backend Scala](https://github.com/dubinsky/scalajs-gradle) - has to provide a throwable to Gradle, which requires one to accompany a test failure, and if it is not propagated by the test framework, a fake throwable has to be concocted (ugh).

This change makes the ends meet ;)
@dubinsky dubinsky force-pushed the less-discarding-of-test-failure-throwables branch from c899da4 to 9f9cd98 Compare August 12, 2025 15:33
@dubinsky
Copy link
Contributor Author

My only concern (which doesn't need to be addressed) is that we're only taking the first failure and discarding others.

Yes, this asymmetricity bothers me too; but for test failure reporting, one - any one! - is better than none...

Copy link
Collaborator

@Baccata Baccata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good enough for now, in the sense that it makes the library better for a rather niche usecase without impacting the majority.

@dubinsky
Copy link
Contributor Author

Reporting the cause of the test failure does not seem like an niche use case to me; do I need to do anything for this to get merged?
Thank you!

@dubinsky
Copy link
Contributor Author

A little more context: there is no throwable in the sbt.testing.Event reporting failure of pureTest("failure"){ expect(0 == 1) }; I suspect that the cause is that that such singular-seeming failures are packaged as Result.Failures (plural) and not Result.Failure (singular); if that is true, in addition to the proposed change, mistaken packaging of a single failure into Result.Failures (plural) should be fixed - by you ;)

Thanks!

@Baccata
Copy link
Collaborator

Baccata commented Aug 14, 2025

if that is true, in addition to the proposed change, mistaken packaging of a single failure into Result.Failures

That is what I meant. My point is that if mistake there is, you're the first reporter in years being noticeably impacted by it, hence the "niche" denomination. I presume the use of Gradle is what led for this to be noticed, and Gradle is a somewhat niche build-tool in the Scala community. Didn't mean anything more by it, providing a mitigation is indeed important.

We can start with the mitigation you implemented in this PR and take the time to assess what should be done for a more proper fix.

@Baccata Baccata merged commit 80ad285 into typelevel:main Aug 14, 2025
13 checks passed
@dubinsky
Copy link
Contributor Author

Thanks!

@dubinsky
Copy link
Contributor Author

We can start with the mitigation you implemented in this PR and take the time to assess what should be done for a more proper fix.

@Baccata I think #186 is what should be done ;)

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.

3 participants