Skip to content

Conversation

ericproulx
Copy link
Owner

@ericproulx ericproulx commented Jul 10, 2025

Summary

This PR refactors the integration of endpoint helpers and error middleware in Grape, focusing on clarity, maintainability, and improved error handling. The changes are motivated by the need to simplify the endpoint lifecycle, ensure correct helper inclusion, and make error handling more robust and intuitive.

Key Changes

  • Endpoint Helpers Refactor:

    • Helpers are now included via at endpoint initialization, ensuring they are available in the endpoint context without polluting the global scope.
    • The lazy initialization logic is simplified, and the block handling for endpoints is made more explicit and robust.
  • Middleware Error Handling:

    • The dynamic inclusion of helpers in is removed. Error handlers always been executed in the context of the endpoint.
    • The error handler logic is updated to use the endpoint's method for symbol handlers, improving encapsulation and error reporting.
  • Spec Update:

    • The spec is updated to expect a instead of a when a rescue handler method is missing, reflecting the new error handling approach.

Motivation

  • Reduces complexity in how helpers are managed and included in endpoints.
  • Ensures that error handling is always performed in the correct context, avoiding subtle bugs and making the codebase easier to reason about.
  • Aligns error reporting with Ruby conventions, making debugging and maintenance easier for contributors.

Impact

  • No breaking changes to the public API, but internal behavior is more predictable and maintainable.
  • Error messages for missing rescue handlers are now more accurate and Ruby-idiomatic.
  • The codebase is easier to extend for future improvements in endpoint and middleware behavior.

Please review the implementation and let me know if further clarifications or tests are needed.

@ericproulx ericproulx force-pushed the revisit_endpoint_helpers_and_new branch from 268bfc8 to 32db385 Compare July 10, 2025 20:01
@coveralls
Copy link

coveralls commented Jul 10, 2025

Pull Request Test Coverage Report for Build 16206424429

Details

  • 14 of 14 (100.0%) changed or added relevant lines in 2 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.03%) to 98.196%

Files with Coverage Reduction New Missed Lines %
lib/grape/middleware/error.rb 2 93.65%
Totals Coverage Status
Change from base Build 16180762547: -0.03%
Covered Lines: 3375
Relevant Lines: 3437

💛 - Coveralls

@ericproulx ericproulx force-pushed the revisit_endpoint_helpers_and_new branch 2 times, most recently from 56e1d61 to b972cec Compare July 10, 2025 20:10
Fix spec
@ericproulx ericproulx force-pushed the revisit_endpoint_helpers_and_new branch from b972cec to c6b72d8 Compare July 10, 2025 21:29
@ericproulx ericproulx merged commit 2dd0bd9 into master Jul 12, 2025
92 of 93 checks passed
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.

2 participants