rails/rails · error · ArgumentError

Expected name: to be a String, got #{name.class}

Error message

Expected name: to be a String, got #{name.class}

What it means

Error "Expected name: to be a String, got #{name.class}" thrown in rails/rails.

Source

Thrown at actionpack/lib/action_controller/metal/http_authentication.rb:80

    #     def test_access_granted_from_xml
    #       authorization = ActionController::HttpAuthentication::Basic.encode_credentials(users(:dhh).name, users(:dhh).password)
    #
    #       get "/notes/1.xml", headers: { 'HTTP_AUTHORIZATION' => authorization }
    #
    #       assert_equal 200, status
    #     end
    module Basic
      extend self

      module ControllerMethods
        extend ActiveSupport::Concern

        module ClassMethods
          # Enables HTTP Basic authentication.
          #
          # See ActionController::HttpAuthentication::Basic for example usage.
          def http_basic_authenticate_with(name:, password:, realm: nil, message: nil, content_type: nil, **options)
            raise ArgumentError, "Expected name: to be a String, got #{name.class}" unless name.is_a?(String)
            raise ArgumentError, "Expected password: to be a String, got #{password.class}" unless password.is_a?(String)
            before_action(options) { http_basic_authenticate_or_request_with name: name, password: password, realm: realm, message: message, content_type: content_type }
          end
        end

        def http_basic_authenticate_or_request_with(name:, password:, realm: nil, message: nil, content_type: nil)
          authenticate_or_request_with_http_basic(realm, message, content_type) do |given_name, given_password|
            # This comparison uses & so that it doesn't short circuit and uses
            # `secure_compare` so that length information isn't leaked.
            ActiveSupport::SecurityUtils.secure_compare(given_name.to_s, name) &
              ActiveSupport::SecurityUtils.secure_compare(given_password.to_s, password)
          end
        end

        def authenticate_or_request_with_http_basic(realm = nil, message = nil, content_type = nil, &login_procedure)
          authenticate_with_http_basic(&login_procedure) || request_http_basic_authentication(realm || "Application", message, content_type)
        end

View on GitHub (pinned to 817fc2a147)

When it happens

Trigger: Thrown at actionpack/lib/action_controller/metal/http_authentication.rb:80 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rails/rails@817fc2a147 (2026-08-04). Data as JSON: /data/errors/45e9f1cd1376ea6d.json. Report an issue: GitHub.