Skip to content

Conversation

@ericproulx
Copy link
Contributor

Update UPGRADING notes regarding return usage and simplify endpoint execution

Summary

This PR simplifies the endpoint execution code and improves the deprecation messaging for using return in endpoint blocks. It removes an unnecessary lambda wrapper and clarifies in documentation that developers should use next instead of return.

Changes

Code Simplification

  • Simplified Grape::Endpoint#initialize: Removed the unnecessary @block lambda wrapper that was created around the source block. The endpoint now directly stores the source block in @source.

  • Simplified Grape::Endpoint#execute: Moved the execution logic directly into the execute method instead of wrapping it in a lambda. The method now:

    • Directly calls instance_exec(&@source) when a source block exists
    • Maintains the same instrumentation with ActiveSupport::Notifications
    • Preserves the deprecation warning behavior for LocalJumpError (when return is used)

Documentation Updates

  • Updated UPGRADING.md: Added clarification that developers should use next instead of return when exiting early from endpoint blocks.

Test Updates

  • Updated deprecation warning test: Modified the test expectation to match the updated warning message that now includes "Use next instead" guidance.

Benefits

  1. Cleaner code: Removes an unnecessary abstraction layer (the lambda wrapper)
  2. Better developer experience: The deprecation warning now provides actionable guidance on what to use instead
  3. Consistency: The code structure is more straightforward and easier to understand

Related Issues/PRs

Related to #2577 where return in endpoint execution was initially deprecated.

Testing

  • Existing tests pass
  • The deprecation warning test has been updated to verify the new warning message
  • Behavior remains backward compatible (using return still works but shows a deprecation warning)

@ericproulx ericproulx requested a review from dblock November 1, 2025 13:13
@ericproulx ericproulx force-pushed the update_return_upgrading_notes_and_simplify_execute branch from 1c6195b to 005c71d Compare November 1, 2025 13:14
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

My usual nitpick, sorry! Fix and merge.

@ericproulx ericproulx force-pushed the update_return_upgrading_notes_and_simplify_execute branch from 005c71d to e90ed9b Compare November 1, 2025 21:17
@ericproulx ericproulx force-pushed the update_return_upgrading_notes_and_simplify_execute branch from e90ed9b to 1857d26 Compare November 1, 2025 21:22
ericproulx and others added 2 commits November 1, 2025 23:49
Co-authored-by: Daniel (dB.) Doubrovkine <[email protected]>
Co-authored-by: Daniel (dB.) Doubrovkine <[email protected]>
@dblock dblock merged commit cc82601 into master Nov 1, 2025
103 checks passed
@dblock dblock deleted the update_return_upgrading_notes_and_simplify_execute branch November 1, 2025 23:56
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