{"record":{"id":"928b738033d9aa70","repo":"ruby-grape/grape","slug":"grape-helper-method-name-overrides-grape-en","errorCode":null,"errorMessage":"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.","messagePattern":"Grape: helper method `#(.+?)` overrides Grape::Endpoint##(.+?)\\. The helper takes precedence\\. To use the framework implementation, remove the helper\\. Silence this warning by setting Grape\\.config\\.warn_on_helper_overrides = false\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/grape/dsl/helpers.rb","lineNumber":90,"sourceCode":"        mod.extend(BaseHelper) unless mod.is_a?(BaseHelper)\n        yield if block\n        warn_on_endpoint_overrides(mod) if Grape.config.warn_on_helper_overrides\n        mod.api_changed(self)\n      end\n\n      # When +Grape.config.warn_on_helper_overrides+ is enabled, emit a\n      # warning to +$stderr+ for any helper method that masks an instance\n      # method on +Grape::Endpoint+. Helpers are mixed into the endpoint's\n      # singleton class and therefore take precedence over +Endpoint+\n      # instance methods — usually intentional, but a common source of\n      # surprise when the framework gains a method that already collides\n      # with an existing helper name.\n      def warn_on_endpoint_overrides(mod)\n        overridden = mod.instance_methods(false).select { |m| Grape::Endpoint.method_defined?(m) }\n        return if overridden.empty?\n\n        overridden.each do |name|\n          warn(\n            \"Grape: helper method `#{name}` overrides Grape::Endpoint##{name}. \" \\\n            'The helper takes precedence. To use the framework implementation, remove the helper. ' \\\n            'Silence this warning by setting Grape.config.warn_on_helper_overrides = false.'\n          )\n        end\n      end\n\n      # This module extends user defined helpers\n      # to provide some API-specific functionality.\n      module BaseHelper\n        attr_accessor :api\n\n        def params(name, &block)\n          @named_params ||= {}\n          @named_params[name] = block\n        end\n\n        def api_changed(new_api)","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/ruby-grape/grape/blob/22d7975629846a3c0c7bd2b34e140a7a1b4af8f6/lib/grape/dsl/helpers.rb#L72-L108","documentation":"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.","triggerScenarios":"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`, ...).","commonSituations":"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).","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"],"exampleFix":"# before\nhelpers do\n  def params\n    # shadows Grape::Endpoint#params\n  end\nend\n\n# after\nhelpers do\n  def sanitized_params\n    # framework `params` still reachable\n  end\nend","handlingStrategy":"validation","validationCode":"def endpoint_collisions(helper_mod)\n  helper_mod.instance_methods(false).select { |m| Grape::Endpoint.method_defined?(m) }\nend\n\ncollisions = endpoint_collisions(MyHelpers)\nwarn \"helpers shadow Endpoint methods: #{collisions.join(', ')}\" unless collisions.empty?","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["grape","helpers","endpoint","shadowing","warning"],"backgroundTag":"method-override-shadowing","analyzedSha":"22d7975629846a3c0c7bd2b34e140a7a1b4af8f6","analyzedAt":"2026-08-21T17:03:54.627Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}