Skip to content

Handle undefined and ambiguous without throwing#33

Merged
davidjgoss merged 7 commits into
mainfrom
undefined-ambiguous-dont-throw
Nov 27, 2025
Merged

Handle undefined and ambiguous without throwing#33
davidjgoss merged 7 commits into
mainfrom
undefined-ambiguous-dont-throw

Conversation

@davidjgoss
Copy link
Copy Markdown
Member

@davidjgoss davidjgoss commented Nov 27, 2025

🤔 What's changed?

The prepare() method used to throw an error if the step was undefined (no matching definitions) or ambiguous (> 1 matching definitions). This originated from https://github.com/cucumber/cucumber-node where we have to have such steps bubble up as an error for the test runner, but otherwise it means we're using exceptions for control flow which is better avoided.

This PR changes the behaviour so that we return an object for an undefined or ambiguous step. The consumer can then handle that as desired, including by throwing - the error classes are still here and have been recast to accept those return objects as their input, for convenience - or whatever else.

Also, UndefinedError optionally accepts a list of snippets too, so those can be included in the user-facing error message once the consuming implementation has written them.

🏷️ What kind of change is this?

  • 🏦 Refactoring/debt/DX (improvement to code design, tooling, etc. without changing behaviour)
  • 💥 Breaking change (incompatible changes to the API)

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

This text was originally generated from a template, then edited by hand. You can modify the template here.

@davidjgoss davidjgoss marked this pull request as ready for review November 27, 2025 09:13
@davidjgoss davidjgoss merged commit 1f5c56b into main Nov 27, 2025
11 checks passed
@davidjgoss davidjgoss deleted the undefined-ambiguous-dont-throw branch November 27, 2025 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant