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

Unwrap AssertionError from InvocationTargetException during Quarkus JUnit5 callbacks #35646

Merged
merged 1 commit into from
Sep 1, 2023

Conversation

msavy
Copy link
Contributor

@msavy msavy commented Aug 30, 2023

I have been writing some custom Quarkus JUnit 5 callbacks; these are specially provided by Quarkus to allow callbacks within the context of the Quarkus classloader to do things like CDI, etc.

I've generally managed to get most things working after experimentation, plus digging through code and documentation, but there was one nit:

Currently, only RuntimeException-derived throwables are being unwrapped, but many test frameworks use throwables deriving from AssertionError. Hence, if an AssertionError is thrown in the callback, it currently ends up being wrapped by an InvocationTargetException, which means that tooling doesn't parse the stack trace properly for "expected" vs "actual" comparisons, etcetera.

This small pull request ensures that AssertionError is unwrapped properly (but not Error more generically, as this could mask categories of error that emanate from other sources such as OOM, where leaving it unwrapped may be helpful).

I added a test that exercises the existing codepaths as well as the new one.

p.s: I initially tried to add the tests to existing @QuarkusTests that cover callbacks, but despite sinking many hours into it, I couldn't find a sensible way to capture the exceptions thrown from the Quarkus callbacks inside of the JUnit test, so this semi-mocked approach seems the most practical way without significant code changes, which I doubt are worth it.

@quarkus-bot
Copy link

quarkus-bot bot commented Aug 30, 2023

Thanks for your pull request!

The title of your pull request does not follow our editorial rules. Could you have a look?

  • title should not end up with dot

This message is automatically generated by a bot.

@msavy msavy changed the title Unwrap AssertionError from InvocationTargetException during Quarkus JUnit5 callbacks. Unwrap AssertionError from InvocationTargetException during Quarkus JUnit5 callbacks Aug 30, 2023
@msavy msavy force-pushed the unwrap-callback-assertion-error branch 4 times, most recently from 7166640 to fb42cc1 Compare August 30, 2023 20:54
…us JUnit5 callbacks.

Previously, only `RuntimeException` derived throwables were unwrapped, but many test frameworks
use throwables deriving from `AssertionError`, so this should be handled also.
@msavy msavy force-pushed the unwrap-callback-assertion-error branch from fb42cc1 to 7b9cb7d Compare August 30, 2023 21:00
Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

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

Thanks!

@geoand geoand added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Aug 31, 2023
@msavy
Copy link
Contributor Author

msavy commented Aug 31, 2023

@geoand CI doesn't seem to be triggering for some reason

@msavy
Copy link
Contributor Author

msavy commented Aug 31, 2023

GH workflows says it is still waiting for approval from a maintainer, which you are, so not sure why it's not picking it up.

@geoand
Copy link
Contributor

geoand commented Aug 31, 2023

Done!

@quarkus-bot
Copy link

quarkus-bot bot commented Aug 31, 2023

✔️ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

@geoand geoand merged commit 4c0340a into quarkusio:main Sep 1, 2023
@quarkus-bot quarkus-bot bot added this to the 3.4 - main milestone Sep 1, 2023
@quarkus-bot quarkus-bot bot removed the triage/waiting-for-ci Ready to merge when CI successfully finishes label Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants