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

System.Reflection.TargetInvocationException is throwing instead of actual step exception #347

Open
undron opened this issue May 19, 2023 · 4 comments

Comments

@undron
Copy link
Contributor

undron commented May 19, 2023

Consider this code:

        [AllureStep("This step should fail")]
        public static int FailedStep()
        {
            var x = 1;
            return 1 / (1 - x);
        }

        [Test]
        [AllureName("Should fail on step")]
        public void ReturnFail()
        {
            FailedStep();
        }

This test failed with exception:

System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  ----> System.DivideByZeroException : Attempted to divide by zero.

but should be failed with System.DivideByZeroException : Attempted to divide by zero.

  • Allure version: 2.9.5-preview.1
@vladdex
Copy link

vladdex commented May 23, 2024

@unickq Are there any plans to address this issue ? This is especially problematic when trying to handle exception thrown by other step methods:
Ex: trying to catch a timeout exception thrown by a WebDriverWait.

@delatrie
Copy link
Contributor

Hi, @vladdex
What runtime do you use?

@vladdex
Copy link

vladdex commented May 23, 2024

@delatrie I'm reproducing this in dotnet 8.
Accessing the InnerException property of the TargetInvocationException reveals the actual exception.

@driverog
Copy link

Hello, I also faced this same issue, as a workaround, you can have a look at my solution in the discussion section of the Allure organization. It involves creating an aspect around the base aspect to handle this exception and unwrap it.
https://github.com/orgs/allure-framework/discussions/2590#discussioncomment-9830924

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

4 participants