padrino/padrino-framework · error

Please, do not use `register` on Padrino::Application object

Error message

Please, do not use `register` on Padrino::Application object, use `.dup` or subclassing

What it means

Padrino::Rendering#registered raises when a module is registered directly on the Padrino::Application base class (app == Padrino::Application). Registering on the base class would mutate engine configuration and settings shared by every Padrino app in the process, so Padrino forces you to apply modules to a subclass or a duplicate instead.

Source

Thrown at padrino-helpers/lib/padrino/rendering.rb:63

    ##
    # Default options used in the resolve_template-method.
    #
    DEFAULT_RENDERING_OPTIONS = { strict_format: false, raise_exceptions: true } unless defined?(DEFAULT_RENDERING_OPTIONS)

    class << self
      ##
      # Default engine configurations for Padrino::Rendering.
      #
      # @return {Hash<Symbol,Hash>}
      #   The configurations, keyed by engine.
      def engine_configurations
        @engine_configurations ||= {}
      end

      def registered(app)
        if defined?(Padrino::Application) && app == Padrino::Application
          # this fail can be removed later when jRuby is not bugged and MRI19 is dropped
          raise 'Please, do not use `register` on Padrino::Application object, use `.dup` or subclassing'
        end
        included(app)
        engine_configurations.each do |engine, configs|
          app.set engine, configs
        end
      end

      def included(base)
        base.send(:include, InstanceMethods)
        base.extend(ClassMethods)
      end
    end

    ##
    # Class methods responsible for rendering templates as part of a request.
    #
    module ClassMethods
      ##

View on GitHub (pinned to 167044f3d5)

Solutions

  1. Create an app subclass and register inside it: class MyApp < Padrino::Application; register MyModule; end
  2. If you need a disposable base class, use Padrino::Application.dup and register on the copy
  3. For libraries, ship a plain module that users register inside their own app subclass instead of touching Padrino::Application

Example fix

# before
Padrino::Application.register MyModule

# after
class MyApp < Padrino::Application
  register MyModule
end
Defensive patterns

Strategy: validation

Validate before calling

def safe_register(app, mod)
  raise 'register on an app subclass, not Padrino::Application' if app.equal?(Padrino::Application)
  app.register(mod)
end

Type guard

def padrino_app_subclass?(klass)
  klass.is_a?(Class) && klass < Padrino::Application && !klass.equal?(Padrino::Application)
end

Prevention

When it happens

Trigger: Calling Padrino::Application.register MyModule at the top level; using the old Padrino 0.9 pattern Padrino::Application.register Padrino::Rendering; any register helper invocation whose app argument is exactly the Padrino::Application class object.

Common situations: Migrating a Sinatra app where Sinatra::Application.register was idiomatic; following outdated tutorials or books that show registration on the base class; gem authors trying to auto-register their module with the framework globally on load.

Related errors


AI-assisted analysis of padrino/padrino-framework@167044f3d5 (2026-08-23). Data as JSON: /api/errors/d543edd85718c8d2. Report an issue: GitHub.