Skip to content

Conversation

@ericproulx
Copy link
Contributor

Revert PR #2577: Restore support for return in endpoint blocks

Summary

This PR reverts the changes introduced in PR #2577 that deprecated the use of return in endpoint blocks and simplified endpoint block execution. Based on the discussion in PR #2577, we are restoring the previous behavior that allows return statements to work without deprecation warnings.

Background

PR #2577 ("Simplify endpoint block execution and deprecate return call in it") changed how endpoint blocks are executed by:

  • Using instance_exec instead of converting blocks to unbound methods
  • Catching LocalJumpError exceptions and issuing deprecation warnings when return was used
  • Recommending the use of next instead of return

After further discussion, it was decided to revert these changes to maintain backward compatibility and restore the original behavior.

Changes

Endpoint Block Execution (lib/grape/endpoint.rb)

  • Restored block_to_unbound_method class method: Converts blocks to unbound methods for proper return handling
  • Restored unbound method binding: Changed from instance_exec(&@source) back to @source.bind_call(self)
  • Removed deprecation warning: Removed the LocalJumpError rescue block that issued deprecation warnings for return statements

Tests (spec/grape/endpoint_spec.rb)

  • Simplified return test: Removed deprecation warning expectations
  • Removed next test: No longer needed since return is the supported approach again

Impact

Related

  • Reverts: #2577 - Simplify endpoint block execution and deprecate return call in it

@ericproulx ericproulx force-pushed the feature/return_of_return branch from 18bda7a to 65fd456 Compare December 13, 2025 22:14
@ericproulx
Copy link
Contributor Author

After this merge, we should release a 3.0.2.

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.

Rebase, feel free to merge.

@ericproulx ericproulx force-pushed the feature/return_of_return branch from 65fd456 to 0ac4b32 Compare December 15, 2025 20:54
@ericproulx ericproulx merged commit 886b13a into master Dec 15, 2025
108 of 109 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.

3 participants