Uncaught exception in client code does not release contextReference object in ScenarioScope
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- cpp
- 领域
- testing-qa
调研方向
从 CukeCommands::endScenario 开始,跟踪 HookRegistrar::execAfterHooks、contextManager.purgeContexts 和 currentScenario.reset()。将 hook 的处理与 BasicStep::invoke 进行比较。当 AFTER hook 抛出异常时仍能释放 scenario context,且后续 scenario 仍保持隔离,同时报告 hook 错误,而不是将其表现为无关的 wire-server 故障,即视为完成。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- C++
- 星标
- 330
- 派生
- 142
- 平均合并
- 2 天 8 小时
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
cucumber/cucumber-cpp 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 45/100
cucumber/cucumber-cpp#317 ·
-
难度 5/5 一周以上 新手友好度 20/100
cucumber/cucumber-cpp#313 · 9 条评论 ·
-
Authorize hyphen "-" for Tag可能重新可做 @ursfassler 于 399 天前认领,目前没有进行中的 PR。 未关闭bug
cucumber/cucumber-cpp#312 · 4 条评论 · 已指派 1 人 ·
-
feature
难度 4/5 3-5 天 新手友好度 35/100
cucumber/cucumber-cpp#304 · 2 条评论 ·
-
help
难度 4/5 3-5 天 新手友好度 25/100
cucumber/cucumber-cpp#302 · 1 条评论 ·
查看 cucumber/cucumber-cpp 的全部 Issue
相似的 Issue
-
Build fails on macOS 27: dyld refuses stripped Rust proc-macros (mis-aligned LINKEDIT string pool)未关闭
难度 2/5 1-3 小时 新手友好度 73/100
cloudflare/workerd#8963 ·
维护者通常 1 天内回复
-
Android Bug Core Drape
难度 2/5 1-3 小时 新手友好度 77/100
organicmaps/organicmaps#14449 ·
维护者通常 1 天内回复
-
comp-codecs
难度 2/5 1-3 小时 新手友好度 84/100
ClickHouse/ClickHouse#135159 ·
维护者通常 1 天内回复
-
category:port-update
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 2 天内回复
-
difficulty:easy func:python os:windows prio:high type:bug
难度 2/5 1-3 小时 新手友好度 78/100
NatronGitHub/Natron#2029 ·
维护者通常 1 天内回复