Uncaught exception in client code does not release contextReference object in ScenarioScope
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- cpp
- Área
- testing-qa
Línea de trabajo
Comienza con CukeCommands::endScenario y sigue HookRegistrar::execAfterHooks, contextManager.purgeContexts y currentScenario.reset(). Compara el manejo de hooks con BasicStep::invoke. Se considera terminado cuando una excepción de un hook AFTER sigue liberando el contexto del escenario y los escenarios posteriores permanecen aislados, mientras que el error del hook se informa en lugar de manifestarse como un fallo no relacionado del wire-server.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- C++
- Estrellas
- 330
- Forks
- 142
- Merge medio
- 2 d 8 h
- PR fusionados (30 d)
- 2
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de cucumber/cucumber-cpp
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
cucumber/cucumber-cpp#317 ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
cucumber/cucumber-cpp#313 · 9 comentarios ·
-
Authorize hyphen "-" for TagQuizá libre de nuevo @ursfassler la tomó hace 399 días y no hay ningún pull request abierto. Abiertobug
cucumber/cucumber-cpp#312 · 4 comentarios · 1 asignado ·
-
feature
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
cucumber/cucumber-cpp#304 · 2 comentarios ·
-
Cucumber for MakefileAbiertohelp
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
cucumber/cucumber-cpp#302 · 1 comentario ·
Todos los issues de cucumber/cucumber-cpp
Issues similares
-
Build fails on macOS 27: dyld refuses stripped Rust proc-macros (mis-aligned LINKEDIT string pool)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
cloudflare/workerd#8963 ·
Los mantenedores suelen responder en 1 día
-
Android Bug Core Drape
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
organicmaps/organicmaps#14449 ·
Los mantenedores suelen responder en 1 día
-
comp-codecs
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
ClickHouse/ClickHouse#135159 ·
Los mantenedores suelen responder en 1 día
-
[raygui] update to 5.0Abiertocategory:port-update
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
Los mantenedores suelen responder en 2 días
-
difficulty:easy func:python os:windows prio:high type:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NatronGitHub/Natron#2029 ·
Los mantenedores suelen responder en 1 día