Uncaught exception in client code does not release contextReference object in ScenarioScope
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- cpp
- Ambito
- testing-qa
Direzione di ricerca
Inizia da CukeCommands::endScenario e segui HookRegistrar::execAfterHooks, contextManager.purgeContexts e currentScenario.reset(). Confronta la gestione degli hook con BasicStep::invoke. Il lavoro è completato quando un’eccezione proveniente da un hook AFTER rilascia comunque il contesto dello scenario e gli scenari successivi rimangono isolati, mentre l’errore dell’hook viene segnalato invece di manifestarsi come un errore non correlato del wire-server.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
When the test client code has a function call inside After step and this function call throws an exception, then cucumber-cpp does not catch this error on server side thus yields undefined behavior. This uncaught exception causes endScenario() function abort and won't release the current scenario scope from memory. This impacts all the scenarios after this and causes undefined method '[]' for nil:NilClass (NoMethodError) error in the wire server. It seems the uncaught exception goes straight into the parser and shadows the real problem.
Expected Behavior
Every each test scenario should be isolated from each other scenario and the hooks should also handle any possible exception to ensure the test scenario remains in stable state. Cucumber should manage the lifetime of the scenario object properly and it should release its resources even if an exception is thrown in the client side.
Current Behavior
The wire server does not support responses on hooks at the moment. If there is an uncaught exception in the after step for example, then the uncaught exception impacts the current test scenario. The endScenario() function stops abruptly without releasing its resources.
The below error message is shown in the console when there is an exception in after step:
undefined method `[]' for nil:NilClass (NoMethodError)
Possible Solution
The endScenario should release the resources of the current scenario even if an exception occurs. A try... catch block should do the trick in this code block like this:
void CukeCommands::endScenario() {
std::exception_ptr eptr;
try {
HookRegistrar::execAfterHooks(currentScenario.get());
} catch (...) {
eptr = std::current_exception();
}
contextManager.purgeContexts();
currentScenario.reset();
if (eptr != nullptr) {
std::rethrow_exception(eptr);
}
}
This fix on its own would not fix the problem altogether however... The Hook object should also implement methods that communicates with the wire server and reports any possible errors that might occur. The Hook class should have similar behavior as BasicStep and it should return the InvokeResult accordingly.
InvokeResult BasicStep::invoke(const InvokeArgs *pArgs) {
this->pArgs = pArgs;
currentArgIndex = 0;
currentResult = InvokeResult::success();
try {
InvokeResult returnedResult = invokeStepBody();
if (currentResult.isPending()) {
return currentResult;
} else {
return returnedResult;
}
} catch (const std::exception& ex) {
return InvokeResult::failure(ex.what());
} catch (const std::string& ex) {
return InvokeResult::failure(ex);
} catch (const char *ex) {
return InvokeResult::failure(ex);
} catch (...) {
// Cucumber needs a description here
return InvokeResult::failure("Unknown exception");
}
}
Steps to Reproduce (for bugs)
- In your test code, create an AFTER() step.
- Place a simple throw -1 inside it.
- See what happens.
Context & Motivation
We are using cucumber-cpp to test the behavior of our product.
Your Environment
- Version used: 0.4
- Operating System and version: Windows 10
- Lingua principale
- C++
- Stelle
- 330
- Fork
- 142
- Merge medio
- 2g 8h
- PR unite (30g)
- 2
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 cucumber/cucumber-cpp
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
cucumber/cucumber-cpp#317 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
cucumber/cucumber-cpp#313 · 9 commenti ·
-
Authorize hyphen "-" for TagForse di nuovo libera @ursfassler l’ha presa 399 giorni fa e non c’è nessuna pull request aperta. Apertabug
cucumber/cucumber-cpp#312 · 4 commenti · 1 assegnatario ·
-
feature
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
cucumber/cucumber-cpp#304 · 2 commenti ·
-
Cucumber for MakefileApertahelp
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
cucumber/cucumber-cpp#302 · 1 commento ·
Tutte le issue di cucumber/cucumber-cpp
Issue simili
-
Build fails on macOS 27: dyld refuses stripped Rust proc-macros (mis-aligned LINKEDIT string pool)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
cloudflare/workerd#8963 ·
I maintainer di solito rispondono entro 1 giorno
-
Android Bug Core Drape
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
organicmaps/organicmaps#14449 ·
I maintainer di solito rispondono entro 1 giorno
-
comp-codecs
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
ClickHouse/ClickHouse#135159 ·
I maintainer di solito rispondono entro 1 giorno
-
difficulty:easy func:python os:windows prio:high type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NatronGitHub/Natron#2029 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
ardazishvili/Sota#114 ·
I maintainer di solito rispondono entro 1 giorno