{"record":{"id":"dba174ccdb653e6f","repo":"lostisland/faraday","slug":"unexpected-params-received-got-params-size-ins","errorCode":null,"errorMessage":"Unexpected params received (got #{params.size} instead of 1)","messagePattern":"Unexpected params received \\(got #(.+?) instead of 1\\)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/faraday/request/authorization.rb","lineNumber":39,"sourceCode":"\n      # @param env [Faraday::Env]\n      def on_request(env)\n        return if env.request_headers[KEY]\n\n        env.request_headers[KEY] = header_from(@type, env, *@params)\n      end\n\n      private\n\n      # @param type [String, Symbol]\n      # @param env [Faraday::Env]\n      # @param params [Array]\n      # @return [String] a header value\n      def header_from(type, env, *params)\n        if type.to_s.casecmp('basic').zero? && params.size == 2\n          Utils.basic_header_from(*params)\n        elsif params.size != 1\n          raise ArgumentError, \"Unexpected params received (got #{params.size} instead of 1)\"\n        else\n          value = params.first\n          if (value.is_a?(Proc) && value.arity == 1) || (value.respond_to?(:call) && value.method(:call).arity == 1)\n            value = value.call(env)\n          elsif value.is_a?(Proc) || value.respond_to?(:call)\n            value = value.call\n          end\n          \"#{type} #{value}\"\n        end\n      end\n    end\n  end\nend\n\nFaraday::Request.register_middleware(authorization: Faraday::Request::Authorization)\n","sourceCodeStart":21,"sourceCodeEnd":55,"githubUrl":"https://github.com/lostisland/faraday/blob/b25b1b26ccef34b1460b0267115be238ca758087/lib/faraday/request/authorization.rb#L21-L55","documentation":"Faraday::Request::Authorization builds the Authorization header value in header_from. The contract is: for the 'basic' scheme exactly two params (user, password) are required and are base64-joined; for every other scheme exactly one param is required — a value, a Proc, or any object responding to #call, optionally taking env to compute the token lazily. Any other count raises ArgumentError telling you how many params were received.","triggerScenarios":"conn.request :authorization, 'Bearer', 'token1', 'token2' (two values for a non-basic scheme); conn.request :authorization, 'Bearer' with no value (zero params); conn.request :authorization, 'Basic', 'user' (basic with one param instead of user+password); splatting an array of auth parts: conn.request :authorization, 'Bearer', *parts where parts.size != 1.","commonSituations":"Migrating from the deprecated conn.authorization / conn.basic_auth helper API and assuming extra args are concatenated; copying curl -H examples with multiple segments; dynamic token code where the token list can be empty; passing user and password to a Bearer scheme by mistake.","solutions":["For non-basic schemes pass exactly one value: conn.request :authorization, 'Bearer', token.","Pre-join multiple segments yourself: \"#{token_type} #{token}\" or join values into one string before passing.","For basic auth pass exactly two params: conn.request :authorization, 'Basic', 'username', 'password' — or use conn.set_basic_auth(user, pass).","When the value must be computed per request, pass a single proc: conn.request :authorization, 'Bearer', ->(env) { token_for(env) }."],"exampleFix":"# before\nconn.request :authorization, 'Bearer', access_token, refresh_token\n# => ArgumentError: Unexpected params received (got 2 instead of 1)\n\n# after\nconn.request :authorization, 'Bearer', access_token\n# computed per request:\nconn.request :authorization, 'Bearer', ->(env) { auth_store.token_for(env) }\n# basic stays two-arg:\nconn.request :authorization, 'Basic', 'user', 'pass'","handlingStrategy":"validation","validationCode":"expected = type.to_s.casecmp('basic').zero? ? 2 : 1\nraise ArgumentError, \"auth expects #{expected} value(s)\" unless auth_values.size == expected\nconn.request :authorization, type, *auth_values","typeGuard":"def valid_auth_params?(type, values)\n  type.to_s.casecmp('basic').zero? ? values.size == 2 : values.size == 1\nend","tryCatchPattern":"begin\n  conn.request :authorization, 'Bearer', *auth_args\nrescue ArgumentError => e\n  raise unless e.message.include?('Unexpected params')\n  conn.request :authorization, 'Bearer', auth_args.join(' ')\nend","preventionTips":["Pass exactly one credential value for non-basic schemes; join multi-part values yourself before the call.","Use conn.set_basic_auth(user, pass) or exactly two args for Basic.","For lazy tokens pass a single proc: ->(env) { cache.fetch_token(env) }."],"tags":["ruby","faraday","authorization","middleware","authentication","argumenterror"],"backgroundTag":"wrong-argument-count","analyzedSha":"b25b1b26ccef34b1460b0267115be238ca758087","analyzedAt":"2026-08-21T19:43:20.220Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}