ruby-grape/grape · warning
Grape: helper method `#{name}` overrides Grape::Endpoint##{n
Error message
Grape: helper method `#{name}` overrides Grape::Endpoint##{name}. The helper takes precedence. To use the framework implementation, remove the helper. Silence this warning by setting Grape.config.warn_on_helper_overrides = false. What it means
Helpers are mixed into the endpoint's singleton class and therefore take precedence over methods on `Grape::Endpoint`. When `Grape.config.warn_on_helper_overrides` is enabled (it defaults to false), Grape compares each freshly declared helper name against `Grape::Endpoint`'s instance methods and prints this warning to stderr for every collision — the framework method is shadowed, not called.
Source
Thrown at lib/grape/dsl/helpers.rb:90
mod.extend(BaseHelper) unless mod.is_a?(BaseHelper)
yield if block
warn_on_endpoint_overrides(mod) if Grape.config.warn_on_helper_overrides
mod.api_changed(self)
end
# When +Grape.config.warn_on_helper_overrides+ is enabled, emit a
# warning to +$stderr+ for any helper method that masks an instance
# method on +Grape::Endpoint+. Helpers are mixed into the endpoint's
# singleton class and therefore take precedence over +Endpoint+
# instance methods — usually intentional, but a common source of
# surprise when the framework gains a method that already collides
# with an existing helper name.
def warn_on_endpoint_overrides(mod)
overridden = mod.instance_methods(false).select { |m| Grape::Endpoint.method_defined?(m) }
return if overridden.empty?
overridden.each do |name|
warn(
"Grape: helper method `#{name}` overrides Grape::Endpoint##{name}. " \
'The helper takes precedence. To use the framework implementation, remove the helper. ' \
'Silence this warning by setting Grape.config.warn_on_helper_overrides = false.'
)
end
end
# This module extends user defined helpers
# to provide some API-specific functionality.
module BaseHelper
attr_accessor :api
def params(name, &block)
@named_params ||= {}
@named_params[name] = block
end
def api_changed(new_api)View on GitHub (pinned to 22d7975629)
Solutions
- Rename the helper so it no longer collides (e.g. `params` -> `sanitized_params`)
- If the shadowing is intentional, silence it by leaving `Grape.config.warn_on_helper_overrides` at its default (false)
- Enable the flag in CI after each Grape upgrade to catch newly introduced Endpoint methods that collide
Example fix
# before
helpers do
def params
# shadows Grape::Endpoint#params
end
end
# after
helpers do
def sanitized_params
# framework `params` still reachable
end
end Defensive patterns
Strategy: validation
Validate before calling
def endpoint_collisions(helper_mod)
helper_mod.instance_methods(false).select { |m| Grape::Endpoint.method_defined?(m) }
end
collisions = endpoint_collisions(MyHelpers)
warn "helpers shadow Endpoint methods: #{collisions.join(', ')}" unless collisions.empty? Prevention
- Prefix helper names to avoid framework collisions (e.g. `sanitize_params`, not `params`)
- After each Grape upgrade, run once with `Grape.config.warn_on_helper_overrides = true` in a scratch spec
- Never name a helper after request-state accessors: params, headers, cookies, route, request, env
When it happens
Trigger: Setting `Grape.config.warn_on_helper_overrides = true` and then declaring `helpers do def params; ...; end end` — or any helper whose name matches a public Grape::Endpoint instance method (`headers`, `route`, `cookies`, ...).
Common situations: Upgrading Grape when the framework adds new Endpoint methods that collide with long-standing helper names; auditing a legacy API where a helper silently replaced framework behavior (e.g. a `params` helper that never reaches the real request params).
Related errors
- Grape: rescue_from #{klass} was already registered in this s
- type #{type} should support coercion via `[]`
- #declared is not available prior to parameter validation
- Representation of type #{representation.class} cannot be mer
- Status code must be Integer or Symbol.
AI-assisted analysis of ruby-grape/grape@22d7975629 (2026-08-21).
Data as JSON: /api/errors/928b738033d9aa70.
Report an issue: GitHub.