Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some type checks on the signatures of nested step handlers #647

Merged
merged 8 commits into from
Oct 15, 2024

Conversation

Johnlon
Copy link
Member

@Johnlon Johnlon commented Oct 10, 2024

🤔 What's changed?

This change fixes some type checks on the signatures and runtime return values of the handlers.
This change also improves the quality of the error messages produced.

--

History ...

At some point someone changed the return type for "nested steps" handlers from []string to godog.Steps but they forgot to adjust the type checks where the handlers are registered.

They got away with this because the existing type checks were lax and unable to distinguish []string from godog.Steps.
However, in a couple of places in the code the value is coerced to godog.Steps and so if someone had actually returned []string then the code would blow up at run time rather than during registration.

Additionally there were some tests around these types but they also had not been updated and the test was passing for the wrong reason - the particular test expected an error but the cause of the error was an accident caused by the coercion mentioned above rather than a delibarate act of the test.

⚡️ What's your motivation?

Bug fix and better error handling.

🏷️ What kind of change is this?

  • 🏦 Refactoring/debt/DX (improvement to code design, tooling, etc. without changing behaviour)
  • 🐛 Bug fix (non-breaking change which fixes a defect)

♻️ Anything particular you want feedback on?

I'm pretty sure the change is good - comments please.

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • [ x] I've changed the behaviour of the code
    • [x ] 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.

…]string to godog.Steps but they forgot to adjust the type checks. The existing type checks were lax and unable to distinguish []string from godog.Steps but in a couple of places in the code the value is coerced to godog.Steps and so if someone returned []string then the code would blow up. Additionally there were some tests aroudn these types but they also had not been updated but the test was passing for the wrong reason - the particular test expected an error but the cause of the error wasn't the one the code expected.
Copy link

Go API Changes

# github.com/cucumber/godog
## compatible changes
Attach: added
Attachment: added
Attachments: added
ErrAmbiguous: added
StepAmbiguous: added

# github.com/cucumber/godog/formatters
## incompatible changes
Formatter.Ambiguous: added

# summary
Inferred base version: v0.14.1
Suggested version: v0.15.0

@Johnlon
Copy link
Member Author

Johnlon commented Oct 10, 2024

@mpkorstanje @vearutop - mind taking a look please.

The PR description explains it all.
Pretty sure this is all good but wouldn't mind some other eyes.

@@ -179,9 +179,6 @@ func fmtOutputTest(fmtName, testName, featureFilePath string) func(*testing.T) {
expected := normalise(string(expectedOutput))
actual := normalise(buf.String())
assert.Equalf(t, expected, actual, "path: %s", expectOutputPath)
if expected != actual {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed some junk

… problem is the function signature and not the args being passed to the function, also added numerous extra assertions on the precise error messages returned. Now that the precise error is being verified in the test I have improved certain error messages to that more accurate detail is included in the errors
@mpkorstanje mpkorstanje changed the title at some point someone changed the return type for nested steps from [… Fix some type checks on the signatures of nested step handlers Oct 11, 2024
@mpkorstanje
Copy link
Contributor

The PR looks reasonable but I don't have enough familiarity to review Go.

Copy link
Member

@vearutop vearutop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@Johnlon Johnlon merged commit 223efc3 into main Oct 15, 2024
5 checks passed
@Johnlon Johnlon deleted the fix-handler-typechecks branch October 15, 2024 12:25
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.

3 participants