Uncaught exception in client code does not release contextReference object in ScenarioScope
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- cpp
- 領域
- testing-qa
調査の方向性
CukeCommands::endScenario から始めて、HookRegistrar::execAfterHooks、contextManager.purgeContexts、currentScenario.reset() を追跡します。フックの処理を BasicStep::invoke と比較します。AFTER フックで例外が発生してもシナリオコンテキストが解放され、後続のシナリオが分離されたままになり、フックのエラーが報告されて 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時間
- マージ済み PR(30日)
- 2
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
cucumber/cucumber-cpp のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
cucumber/cucumber-cpp#317 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
cucumber/cucumber-cpp#313 · コメント 9 件 ·
-
Authorize hyphen "-" for Tag再び着手できるかも @ursfassler が 399 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン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 日以内に返信