Skip to content

Java method step failures hide the real error behind InvocationTargetException #808

Closed

Description

@authorjapps

Summary

When a custom Java Executor(or Answerer) method (a step with a url such as org.example.MyExecutor) throws an exception, the error log, the step's report message and the JUnit failure message only say Invocation failed for method X in class Y. The executor's own error message is lost.

Users have to search the console stack trace for the Caused by: line to find out what went wrong.

Problem

JavaMethodExecutorImpl.executeWithParams calls the executor through reflection (method.invoke). Any exception the executor throws arrives wrapped in a java.lang.reflect.InvocationTargetException, which has no message of its own. The generic catch block logs and rethrows it as is:

} catch (Exception e) {
    String errMsg = format("Java exec(): Invocation failed for method %s in class %s", methodName, qualifiedClassName);
    LOGGER.error(errMsg + ". Exception - " + e);
    throw new RuntimeException(errMsg, e);
}

For example, if MyExecutor.upload() throws IllegalArgumentException("Could not get OAuth2 token: ..."), users see:

Where What users see today
ERROR log (JavaMethodExecutorImpl) Java exec(): Invocation failed for method upload in class org.example.MyExecutor. Exception - java.lang.reflect.InvocationTargetException
Step exception message in the report (ZeroCodeMultiStepsScenarioRunnerImpl, .exceptionMessage(ex.getMessage())) java.lang.RuntimeException: Java exec(): Invocation failed for method upload in class org.example.MyExecutor
JUnit failure message ZeroCode Step execution failed. Details:java.lang.RuntimeException: Java exec(): Invocation failed for method upload in class org.example.MyExecutor

Could not get OAuth2 token: ... doesn't appears in any of them. It is only in the full stack trace that the runner prints to the console, deep in the output.

The workaround today is for every executor/answer-engine author to catch, log and printStackTrace() in their own code. That duplicates the trace, and it is easy to forget.

Expected behaviour

The message of the exception the executor actually threw should appear in the ERROR log, the report and the JUnit failure message, e.g.:

Java exec(): Invocation failed for method upload in class org.example.MyExecutor. Cause: java.lang.IllegalArgumentException: Could not get OAuth2 token: ...

Proposed fix

Catch InvocationTargetException separately in JavaMethodExecutorImpl.executeWithParams:

  • add the target exception to the message;
  • log the target exception's full stack trace through the logger.

The message prefix and the exception cause chain stay the same, so existing behaviour and tests are unaffected. It is a small change in one file plus a unit test coverage.

Activity

  1. authorjapps commented on Nov 1, 2026

    @authorjapps
    OwnerAuthor

    Hi, I’d like to work on this. Can I take it?

    Hello @CaioSavoldi, thanks for your interest.

    As this was a small change, looks a PR already pending by the new author.

    is it possible for you review this PR please and add any more unit tests(where needed) ?

    Also is it possible to test the feature manually for you and confirm the feature works as expected?

  2. Orcus01 commented on Nov 3, 2026

    @Orcus01
    Collaborator

    Hi, I'd like to help validate the existing fix in #809 rather than duplicate it. I can reproduce the exception-reporting problem, test the PR's behavior, and check whether the underlying executor exception appears in the log, report, and JUnit failure message. If I find missing test coverage, I'll coordinate here before proposing additional tests. Would this testing/review contribution still be useful?

  3. authorjapps commented on Nov 5, 2026

    @authorjapps
    OwnerAuthor

    Hi, ...Would this testing/review contribution still be useful?

    Yes, that'll be really useful @Orcus01 .
    One or two scenarios with the usage and example output will definitely add value to the above PR.

    you can paste the test results here(in this ticket) when you're ready. Thanks in advance.

  4. Orcus01 commented on Nov 5, 2026

    @Orcus01
    Collaborator

    I compared #809 (debef826) with its base (3f91834d) on Java 17.

    1. Executor regression test. mvn -pl core -Dtest=JavaMethodExecutorImplTest test passed all 9 tests on the PR.

    2. JUnit runner. I ran the existing unit_test_files/java_apis/03_test_json_java_service_method_Exception.json fixture using @RunWith(ZeroCodeUnitRunner.class) and @JsonTestCase. The step calls AddService.squareRoot with -255.0. The run failed as expected on both revisions, with these differences in the JUnit error message:

      • Base: Java exec(): Invocation failed for method squareRoot in class org.jsmart.zerocode.core.AddService
      • PR: Java exec(): Invocation failed for method squareRoot in class org.jsmart.zerocode.core.AddService. Cause: java.lang.RuntimeException: Can not square root a negative number

    The executor log on the PR also includes the underlying exception. I verified the JUnit/Surefire output and executor log; I did not confirm that the message is surfaced in the standalone Zerocode report.

  5. authorjapps commented on Nov 6, 2026

    @authorjapps
    OwnerAuthor

    PR: Java exec(): Invocation failed for method squareRoot in class org.jsmart.zerocode.core.AddService. Cause: java.lang.RuntimeException: Can not square root a negative number

    This is great. That shows PR fix is good.


    ...I did not confirm that the message is surfaced in the standalone Zerocode report.

    ok. Do you have mechanism to check this?


    No.2 is not a blocker as long as it works. There were no changes wrt reports feature, but worth checking.

  6. Orcus01 commented on Nov 6, 2026

    @Orcus01
    Collaborator

    I checked the standalone JSON, CSV, and HTML reports using the same negative square-root scenario on the base commit and #809. All three mark the step as FAILED on both revisions. The underlying exception message appears in the executor log and JUnit failure output on #809, but it is absent from the standalone reports on both revisions.

  7. authorjapps commented on Nov 6, 2026

    @authorjapps
    OwnerAuthor

    I checked the standalone JSON, CSV, and HTML reports using the same negative square-root scenario on the base commit and #809. All three mark the step as FAILED on both revisions. The underlying exception message appears in the executor log and JUnit failure output on #809, but it is absent from the standalone reports on both revisions.

    Ah! that needs a fix then 🔴 .

    Would you mind raising a new Issue(BUG) with the examples/tests you used above and attach the report as evidence which is missing the failure description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions