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

Exceptions are swallowed (or not) depending on the Envelope content #2748

Open
jkronegg opened this issue May 10, 2023 · 0 comments
Open

Exceptions are swallowed (or not) depending on the Envelope content #2748

jkronegg opened this issue May 10, 2023 · 0 comments
Labels
🐛 bug Defect / Bug

Comments

@jkronegg
Copy link
Contributor

👓 What did you see?

Let's say I have a plugin which process Envelope and may generate exceptions. Depending on the Envelope content, the exceptions are rethrowed or swallowed by Cucumber:

public class MyPluginPlugin implements EventListener, Plugin {
    private final EventHandler<Envelope> testParameterTypeHandler = (event) -> {
        if (event.getParameterType().isPresent()) {
            throw new RuntimeException("getParameterType");// will be swallowed
        } else if (event.getStepDefinition().isPresent()) {
            throw new RuntimeException("getStepDefinition");// will be swallowed
        } else if (event.getGherkinDocument().isPresent()) {
            throw new RuntimeException("getGherkinDocument");// will be swallowed
        } else if (event.getTestCaseStarted().isPresent()) {
            throw new RuntimeException("getTestCaseStarted");// will be swallowed
        } else if (event.getTestRunFinished().isPresent()) {
            //throw new RuntimeException("getTestRunFinished"); // not swallowed
        }
    };

    public void setEventPublisher(EventPublisher eventPublisher) {
        eventPublisher.registerHandlerFor(Envelope.class, this.testParameterTypeHandler);
    }

}

Note: this is not the real plugin, just a minimalistic one designed to show the problem.

✅ What did you expect to see?

I expect the exceptions generated by the plugin are all rethrown and not swallowed.

📦 Which tool/library version are you using?

Cucumber Java 7.12.0

🔬 How could we reproduce it?

Steps to reproduce the behavior:

  1. create a plugin with the code above
  2. add the plugin to the run configuration of any project which uses Cucumber
  3. run the test with the plugin
  4. no exception is raised

📚 Any additional context?

As a workaround, I currently keep the generated exception aside and throw it when the Envelope contains a TestRunFinished event:

public class MyPluginPlugin implements EventListener, Plugin {
    RuntimeException runtimeException = null;

    private final EventHandler<Envelope> testParameterTypeHandler = (event) -> {
        if (event.getParameterType().isPresent()) {
            runtimeException = new RuntimeException("getParameterType");// will be swallowed
        } else if (event.getStepDefinition().isPresent()) {
            runtimeException = new RuntimeException("getStepDefinition");// will be swallowed
        } else if (event.getGherkinDocument().isPresent()) {
            runtimeException = new RuntimeException("getGherkinDocument");// will be swallowed
        } else if (event.getTestCaseStarted().isPresent()) {
            runtimeException = new RuntimeException("getTestCaseStarted");// will be swallowed
        } else if (event.getTestRunFinished().isPresent()) {
            //throw new RuntimeException("getTestRunFinished"); // not swallowed
            if (runtimeException != null) {
                throw runtimeException;
            }
        }
    };

    public void setEventPublisher(EventPublisher eventPublisher) {
        eventPublisher.registerHandlerFor(Envelope.class, this.testParameterTypeHandler);
    }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug
Projects
None yet
Development

No branches or pull requests

1 participant