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

Root cause is not included when using DataTable.asList and friends #2948

Open
mpkorstanje opened this issue Nov 30, 2024 · 2 comments · May be fixed by #2949
Open

Root cause is not included when using DataTable.asList and friends #2948

mpkorstanje opened this issue Nov 30, 2024 · 2 comments · May be fixed by #2949
Labels
🐛 bug Defect / Bug

Comments

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Nov 30, 2024

👓 What did you see?

While using

    @DataTableType
    public Ingredient mySystemEntry(Map<String, String> entry) {
        throw new IllegalArgumentException("This message is never shown during test execution");
    }

And instead of

    @When("I mix the following ingredients")
    public void i_wait_hour(List<Ingredient> ingredients) {
        // use ingredients here
    }

Using:

	@When("I mix the following ingredients")
	public void i_wait_hour(DataTable dataTable) {
	    List<Ingredient> ingredients = dataTable.asList(Ingredient.class);
	}

Then the stack trace has as a root cause CucumberInvocationTargetException which doesn't show the root cause of the problem.

      io.cucumber.datatable.CucumberDataTableException: 'java.util.List<io.cucumber.skeleton.StepDefinitions$Ingredient>' could not transform
| NAME  | QUANTITY | UNITS |
| Flour | 1        | KG    |
| Water | 0.65     | L     |
| Salt  | 0.08     | KG    |

	at io.cucumber.datatable.DataTableType.transform(DataTableType.java:158)
	at io.cucumber.datatable.DataTableTypeRegistryTableConverter.toListOrProblems(DataTableTypeRegistryTableConverter.java:158)
	at io.cucumber.datatable.DataTableTypeRegistryTableConverter.toList(DataTableTypeRegistryTableConverter.java:139)
	at io.cucumber.datatable.DataTable.asList(DataTable.java:199)
	at io.cucumber.skeleton.StepDefinitions.i_wait_hour(StepDefinitions.java:40)
	at ✽.I mix the following ingredients(classpath:io/cucumber/skeleton/belly.feature:6)
Caused by: io.cucumber.core.backend.CucumberInvocationTargetException
	at io.cucumber.java.Invoker.doInvoke(Invoker.java:73)
	at io.cucumber.java.Invoker.invoke(Invoker.java:24)
	

✅ What did you expect to see?

Some form of abbreviated stack trace.

Scenario: a few cukes                  # io/cucumber/skeleton/belly.feature:3
  Given I have 42 cukes in my belly    # io.cucumber.skeleton.StepDefinitions.I_have_cukes_in_my_belly(int)
  When I mix the following ingredients # io.cucumber.skeleton.StepDefinitions.i_wait_hour(java.util.List<io.cucumber.skeleton.StepDefinitions$Ingredient>)
    | NAME  | QUANTITY | UNITS |
    | Flour | 1        | KG    |
    | Water | 0.65     | L     |
    | Salt  | 0.08     | KG    |
      java.lang.IllegalArgumentException: This message is never shown during test execution
    at io.cucumber.skeleton.StepDefinitions.mySystemEntry(StepDefinitions.java:29)
    at ✽.I mix the following ingredients(classpath:io/cucumber/skeleton/belly.feature:6)

📦 Which tool/library version are you using?

No response

🔬 How could we reproduce it?

No response

📚 Any additional context?

@mpkorstanje mpkorstanje added the 🐛 bug Defect / Bug label Nov 30, 2024
@mpkorstanje
Copy link
Contributor Author

This can probably be fixed by invoking removeFrameworkFramesAndAppendStepLocation recursively.

@jean-michel-gonet
Copy link

Thanks @mpkorstanje for reporting this bug :)

mpkorstanje added a commit that referenced this issue Dec 2, 2024
The `CucumberInvocationTargetException` was originally designed to be
used as a wrapper around `InvocationTargetException` to track the step
definition that caused the exception. The cause of
`InvocationTargetException` would then be rewritten to appear to have
originated from the step definition. This would effectively hide the
whole backend from view.

Unfortunately using DataTable.asList inside a step, this also invokes
the backend. And because `CucumberInvocationTargetException` did not
have cause, the cause of any exceptions would also be hidden.

By exposing the cause of the `InvocationTargetException` as the cause
of the `CucumberInvocationTargetException` and removing any frames
before the step definition was invoked we can clean this up somewhat.

```log
io.cucumber.datatable.CucumberDataTableException: 'java.util.List<io.cucumber.skeleton.StepDefinitions$Ingredient>' could not transform
| NAME  | QUANTITY | UNITS |
| Flour | 1        | KG    |
| Water | 0.65     | L     |
| Salt  | 0.08     | KG    |

	at io.cucumber.datatable.DataTableType.transform(DataTableType.java:158)
	at io.cucumber.datatable.DataTableTypeRegistryTableConverter.toListOrProblems(DataTableTypeRegistryTableConverter.java:158)
	at io.cucumber.datatable.DataTableTypeRegistryTableConverter.toList(DataTableTypeRegistryTableConverter.java:139)
	at io.cucumber.datatable.DataTable.asList(DataTable.java:199)
	at io.cucumber.skeleton.StepDefinitions.i_wait_hour(StepDefinitions.java:40)
	at ✽.I mix the following ingredients(classpath:io/cucumber/skeleton/belly.feature:6)
Caused by: io.cucumber.core.backend.CucumberInvocationTargetException
	at io.cucumber.java.Invoker.doInvoke(Invoker.java:73)
	at io.cucumber.java.Invoker.invoke(Invoker.java:24)
	at io.cucumber.java.AbstractGlueDefinition.invokeMethod(AbstractGlueDefinition.java:47)
	at io.cucumber.java.JavaDataTableTypeDefinition.lambda$createDataTableType$2(JavaDataTableTypeDefinition.java:47)
	at io.cucumber.datatable.DataTableType$TableEntryTransformerAdaptor.transform(DataTableType.java:342)
	at io.cucumber.datatable.DataTableType$TableEntryTransformerAdaptor.transform(DataTableType.java:319)
	at io.cucumber.datatable.DataTableType.transform(DataTableType.java:155)
	... 5 more
Caused by: java.lang.IllegalArgumentException: This message is never shown during test execution
	at io.cucumber.skeleton.StepDefinitions.mySystemEntry(StepDefinitions.java:29)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at io.cucumber.java.Invoker.doInvoke(Invoker.java:66)
	... 11 more
```

Unfortunately, it is not possible to remove the
`CucumberInvocationTargetException` entirely.

Fixes: #2948
@mpkorstanje mpkorstanje linked a pull request Dec 2, 2024 that will close this issue
3 tasks
mpkorstanje added a commit that referenced this issue Dec 2, 2024
The `CucumberInvocationTargetException` was originally designed to be
used as a wrapper around `InvocationTargetException` to track the step
definition that caused the exception. The cause of
`InvocationTargetException` would then be rewritten to appear to have
originated from the step definition. This would effectively hide the
whole backend from view.

Unfortunately using DataTable.asList inside a step, this also invokes
the backend. And because `CucumberInvocationTargetException` did not
have cause, the cause of any exceptions would also be hidden.

By exposing the cause of the `InvocationTargetException` as the cause
of the `CucumberInvocationTargetException` and removing any frames
before the step definition was invoked we can clean this up somewhat.

```log
io.cucumber.datatable.CucumberDataTableException: 'java.util.List<io.cucumber.skeleton.StepDefinitions$Ingredient>' could not transform
| NAME  | QUANTITY | UNITS |
| Flour | 1        | KG    |
| Water | 0.65     | L     |
| Salt  | 0.08     | KG    |

	at io.cucumber.datatable.DataTableType.transform(DataTableType.java:158)
	at io.cucumber.datatable.DataTableTypeRegistryTableConverter.toListOrProblems(DataTableTypeRegistryTableConverter.java:158)
	at io.cucumber.datatable.DataTableTypeRegistryTableConverter.toList(DataTableTypeRegistryTableConverter.java:139)
	at io.cucumber.datatable.DataTable.asList(DataTable.java:199)
	at io.cucumber.skeleton.StepDefinitions.i_wait_hour(StepDefinitions.java:40)
	at ✽.I mix the following ingredients(classpath:io/cucumber/skeleton/belly.feature:6)
Caused by: io.cucumber.core.backend.CucumberInvocationTargetException
	at io.cucumber.java.Invoker.doInvoke(Invoker.java:73)
	at io.cucumber.java.Invoker.invoke(Invoker.java:24)
	at io.cucumber.java.AbstractGlueDefinition.invokeMethod(AbstractGlueDefinition.java:47)
	at io.cucumber.java.JavaDataTableTypeDefinition.lambda$createDataTableType$2(JavaDataTableTypeDefinition.java:47)
	at io.cucumber.datatable.DataTableType$TableEntryTransformerAdaptor.transform(DataTableType.java:342)
	at io.cucumber.datatable.DataTableType$TableEntryTransformerAdaptor.transform(DataTableType.java:319)
	at io.cucumber.datatable.DataTableType.transform(DataTableType.java:155)
	... 5 more
Caused by: java.lang.IllegalArgumentException: This message is never shown during test execution
	at io.cucumber.skeleton.StepDefinitions.mySystemEntry(StepDefinitions.java:29)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at io.cucumber.java.Invoker.doInvoke(Invoker.java:66)
	... 11 more
```

Unfortunately, it is not possible to remove the
`CucumberInvocationTargetException` entirely.

Fixes: #2948
mpkorstanje added a commit that referenced this issue Dec 2, 2024
The `CucumberInvocationTargetException` was originally designed to be
used as a wrapper around `InvocationTargetException` to track the step
definition that caused the exception. The cause of
`InvocationTargetException` would then be rewritten to appear to have
originated from the step definition. This would effectively hide the
whole backend from view.

Unfortunately using DataTable.asList inside a step, this also invokes
the backend. And because `CucumberInvocationTargetException` did not
have cause, the cause of any exceptions would also be hidden.

By exposing the cause of the `InvocationTargetException` as the cause
of the `CucumberInvocationTargetException` and removing any frames
before the step definition was invoked we can clean this up somewhat.

```log
io.cucumber.datatable.CucumberDataTableException: 'java.util.List<io.cucumber.skeleton.StepDefinitions$Ingredient>' could not transform
| NAME  | QUANTITY | UNITS |
| Flour | 1        | KG    |
| Water | 0.65     | L     |
| Salt  | 0.08     | KG    |

	at io.cucumber.datatable.DataTableType.transform(DataTableType.java:158)
	at io.cucumber.datatable.DataTableTypeRegistryTableConverter.toListOrProblems(DataTableTypeRegistryTableConverter.java:158)
	at io.cucumber.datatable.DataTableTypeRegistryTableConverter.toList(DataTableTypeRegistryTableConverter.java:139)
	at io.cucumber.datatable.DataTable.asList(DataTable.java:199)
	at io.cucumber.skeleton.StepDefinitions.i_wait_hour(StepDefinitions.java:40)
	at ✽.I mix the following ingredients(classpath:io/cucumber/skeleton/belly.feature:6)
Caused by: io.cucumber.core.backend.CucumberInvocationTargetException
	at io.cucumber.java.Invoker.doInvoke(Invoker.java:73)
	at io.cucumber.java.Invoker.invoke(Invoker.java:24)
	at io.cucumber.java.AbstractGlueDefinition.invokeMethod(AbstractGlueDefinition.java:47)
	at io.cucumber.java.JavaDataTableTypeDefinition.lambda$createDataTableType$2(JavaDataTableTypeDefinition.java:47)
	at io.cucumber.datatable.DataTableType$TableEntryTransformerAdaptor.transform(DataTableType.java:342)
	at io.cucumber.datatable.DataTableType$TableEntryTransformerAdaptor.transform(DataTableType.java:319)
	at io.cucumber.datatable.DataTableType.transform(DataTableType.java:155)
	... 5 more
Caused by: java.lang.IllegalArgumentException: This message is never shown during test execution
	at io.cucumber.skeleton.StepDefinitions.mySystemEntry(StepDefinitions.java:29)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at io.cucumber.java.Invoker.doInvoke(Invoker.java:66)
	... 11 more
```

Unfortunately, it is not possible to remove the
`CucumberInvocationTargetException` entirely.

Fixes: #2948
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

Successfully merging a pull request may close this issue.

2 participants