Java method step failures hide the real error behind `InvocationTargetException`
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 90/100
Direzione di ricerca
Inizia da JavaMethodExecutorImpl.executeWithParams, dove reflection avvolge gli errori dell’executor in InvocationTargetException. Aggiungi un test per un executor che genera un’eccezione con un proprio messaggio, verificando che il log e l’errore propagato espongano l’eccezione di destinazione preservando il prefisso esistente e la catena delle cause. Esegui la suite di test unitari pertinente per JavaMethodExecutorImpl per confermare il comportamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Java
- Stelle
- 1k
- Fork
- 455
- Merge medio
- 13h 35m
- PR unite (30g)
- 5
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di authorjapps/zerocode
-
#799 Docs (Subissue)Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 35/100
authorjapps/zerocode#802 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 20/100
authorjapps/zerocode#753 · 2 commenti ·
-
FAQ for Java versions(8, 11, 17, 21, 25 LTS) needed or used for your project and CI WorkflowForse di nuovo libera @nirmalchandra l’ha presa 228 giorni fa e non c’è nessuna pull request aperta. Apertadocumentation fixed-and-released
authorjapps/zerocode#748 · 2 commenti · 1 assegnatario ·
-
Add S3 Hook to Enable Zerocode-TDD Steps for Upload, List, and Download ScenariosForse già presa @therev2 l’ha presa 260 giorni fa. Apertaenhancement feature-request good first issue help wanted
authorjapps/zerocode#742 · 7 commenti · 1 assegnatario ·
-
JUnit 6 support ?Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
authorjapps/zerocode#734 · 2 commenti ·
Tutte le issue di authorjapps/zerocode
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
intellij-elixir/intellij-elixir#4585 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
MetricsHub/metricshub-community#1474 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
adorsys/keycloak-config-cli#1742 ·
I maintainer di solito rispondono entro 1 giorno
-
Booking links: POST /api/booking-links with a null element in "availabilityRules" throws NullPointerException and answers 500 instead of 400Forse già presa @chibenwa l’ha presa oggi. Apertaai-driven-fuzzing bug claude Minor
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
linagora/twake-calendar-side-service#1322 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
PathnameExpander incorrectly interprets regex metacharacters in wildcard patternsForse già presa @jiteshkhatri11 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
javapathfinder/jpf-core#662 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno