[#482] Migrated exceptions to use Mink exception classes. #522
[#482] Migrated exceptions to use Mink exception classes. #522AlexSkrypnyk merged 2 commits intomainfrom
Conversation
WalkthroughReplaces generic exception throws across many traits and tests with Behat/Mink-specific exceptions (ExpectationException, ElementNotFoundException, UnsupportedDriverActionException), adds imports and session driver context to thrown exceptions, and updates feature expectations and CLI bootstrap to match new messages. README formatting only. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
5ae3f74 to
6c333ef
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/Drupal/TaxonomyTrait.php (2)
137-154: Consider usingExpectationExceptionfor the vocabulary check at line 141.This method is a "Then" assertion step (
taxonomyAssertTermExistsByName). While the vocabulary not existing is a prerequisite failure, users running this step would expect a Mink-styleExpectationExceptionfor consistency with other assertion methods in this PR.Currently, if the vocabulary doesn't exist, a
RuntimeExceptionis thrown (line 141), but if the term doesn't exist, anExpectationExceptionis thrown (line 152). This inconsistency may confuse users debugging test failures.♻️ Optional: Consistent exception type
if (!$vocab) { - throw new \RuntimeException(sprintf('The vocabulary "%s" does not exist.', $vocabulary_machine_name)); + throw new ExpectationException(sprintf('The vocabulary "%s" does not exist.', $vocabulary_machine_name), $this->getSession()->getDriver()); }
165-182: Same consideration for consistency at line 169.Similar to
taxonomyAssertTermExistsByName, this "Then" assertion method usesRuntimeExceptionfor the vocabulary check butExpectationExceptionfor the term existence check.♻️ Optional: Consistent exception type
if (!$vocab) { - throw new \RuntimeException(sprintf('The vocabulary "%s" does not exist.', $vocabulary_machine_name)); + throw new ExpectationException(sprintf('The vocabulary "%s" does not exist.', $vocabulary_machine_name), $this->getSession()->getDriver()); }
🤖 Fix all issues with AI agents
In `@README.md`:
- Around line 294-314: The fenced code block in the "Exceptions" section
currently uses ``` with no language and triggers markdownlint MD040; update the
block delimiter to include a language identifier (e.g., change ``` to ```text)
so the example error messages (e.g., "Element matching css \"#my-element\" not
found.") are fenced as ```text to satisfy the linter.
In `@src/JavascriptTrait.php`:
- Around line 16-17: Update the docblocks in JavascriptTrait.php to reflect the
actual exception type being thrown: replace any occurrences of "@throws
\Exception" with "@throws \Behat\Mink\Exception\ExpectationException" (or the
fully-qualified Exception used) for the methods in this file (including the
block around lines 282-313) so the `@throws` accurately matches the thrown
ExpectationException referenced by the code.
| ### Exceptions | ||
|
|
||
| - `\Exception` is thrown when an assertion fails. | ||
| - `\RuntimeException` is thrown when a step does not have enough contextual | ||
| information to perform an action. | ||
| This library uses [Mink exception classes](https://mink.behat.org/en/latest/) | ||
| for | ||
| consistent error handling: | ||
|
|
||
| | Exception | When thrown | | ||
| |------------------------------------|------------------------------------------------------| | ||
| | `ElementNotFoundException` | Element, field, link, or selector not found on page | | ||
| | `ExpectationException` | Assertion fails (value mismatch, state verification) | | ||
| | `UnsupportedDriverActionException` | Feature requires specific driver (e.g., Selenium) | | ||
| | `\RuntimeException` | Invalid input or processing error (not an assertion) | | ||
|
|
||
| Example error messages: | ||
|
|
||
| ``` | ||
| Element matching css "#my-element" not found. | ||
| Link with title "My Link" not found. | ||
| Select with id|name|label "My Select" not found. | ||
| The cookie with name "session" was not set. | ||
| ``` |
There was a problem hiding this comment.
Add a language identifier to the fenced code block.
This resolves markdownlint MD040.
🛠️ Suggested fix
-```
+```text
Element matching css "#my-element" not found.
Link with title "My Link" not found.
Select with id|name|label "My Select" not found.
The cookie with name "session" was not set.</details>
<details>
<summary>🧰 Tools</summary>
<details>
<summary>🪛 markdownlint-cli2 (0.18.1)</summary>
309-309: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
</details>
</details>
<details>
<summary>🤖 Prompt for AI Agents</summary>
In @README.md around lines 294 - 314, The fenced code block in the "Exceptions"
section currently uses with no language and triggers markdownlint MD040; update the block delimiter to include a language identifier (e.g., change to
\"#my-element\" not found.") are fenced as ```text to satisfy the linter.
| use Behat\Mink\Exception\ExpectationException; | ||
|
|
There was a problem hiding this comment.
Update the @throws docblock to match the current exception type.
The docblock still says @throws \Exception, which no longer reflects the thrown exception.
Also applies to: 282-313
🤖 Prompt for AI Agents
In `@src/JavascriptTrait.php` around lines 16 - 17, Update the docblocks in
JavascriptTrait.php to reflect the actual exception type being thrown: replace
any occurrences of "@throws \Exception" with "@throws
\Behat\Mink\Exception\ExpectationException" (or the fully-qualified Exception
used) for the methods in this file (including the block around lines 282-313) so
the `@throws` accurately matches the thrown ExpectationException referenced by the
code.
6c333ef to
b0bcec4
Compare
b0bcec4 to
475f623
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #522 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 34 34
Lines 2364 2351 -13
=========================================
- Hits 2364 2351 -13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Closes #482
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.