{"record":{"id":"7f5bd994132f51ab","repo":"jnunemaker/httparty","slug":"bad-argument-expected-uri-adapter-object-or-ur","errorCode":null,"errorMessage":"bad argument (expected #{uri_adapter} object or URI string)","messagePattern":"bad argument \\(expected #(.+?) object or URI string\\)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/httparty/request.rb","lineNumber":87,"sourceCode":"        default_params: {},\n        follow_redirects: true,\n        parser: Parser,\n        uri_adapter: URI,\n        connection_adapter: ConnectionAdapter\n      }.merge(o)\n      self.path = path\n      set_basic_auth_from_uri\n    end\n\n    def path=(uri)\n      uri_adapter = options[:uri_adapter]\n\n      @path = if uri.is_a?(uri_adapter)\n        uri\n      elsif String.try_convert(uri)\n        uri_adapter.parse(uri).normalize\n      else\n        raise ArgumentError,\n          \"bad argument (expected #{uri_adapter} object or URI string)\"\n      end\n    end\n\n    def request_uri(uri)\n      if uri.respond_to? :request_uri\n        uri.request_uri\n      else\n        uri.path\n      end\n    end\n\n    def uri\n      if redirect && path.relative? && path.path[0] != '/'\n        last_uri_host = @last_uri.path.gsub(/[^\\/]+$/, '')\n\n        path.path = \"/#{path.path}\" if last_uri_host[-1] != '/'\n        path.path = \"#{last_uri_host}#{path.path}\"","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/jnunemaker/httparty/blob/8f4a09e343b94de9f934f388028ca97620c9b378/lib/httparty/request.rb#L69-L105","documentation":"Request#path= raises ArgumentError 'bad argument (expected URI object or URI string)' when the path passed to a verb method is neither an instance of the configured uri_adapter nor convertible with String.try_convert. Every HTTParty verb (get/post/put/...) funnels its path through this setter, so passing nil, an Integer, a Symbol, or objects like Pathname that do not define to_str fail here before any connection is opened.","triggerScenarios":"`Foo.get(nil)` (usually an interpolated variable that came back nil), `Foo.get(42)`, `Foo.get(:show)`, `Foo.get(Pathname.new('/tmp/url.txt'))`, or `Foo.get(['http://x'])`. Passing an Addressable::URI while uri_adapter is the default URI also lands here.","commonSituations":"URLs built from ENV vars, DB fields or ERB templates that are nil in some environments, Pathname or URI::Generic objects leaking in from file-handling code, and Addressable objects passed to a client configured with the default URI adapter.","solutions":["Coerce to String at the call site: `Foo.get(url.to_s)` or `Foo.get(url&.to_s)`.","Fail fast on nil upstream: `raise ArgumentError, 'url missing' if url.nil?` before building the request.","When passing Addressable objects, configure `uri_adapter Addressable::URI` on the class."],"exampleFix":"# before\nurl = ENV['ENDPOINT']            # nil when unset\nFoo.get(url)                     # ArgumentError: bad argument\n\n# after\nurl = ENV.fetch('ENDPOINT')\nFoo.get(url)","handlingStrategy":"validation","validationCode":"url = ENV.fetch('ENDPOINT')\nraise ArgumentError, \"path must be a String or #{URI}, got #{url.class}\" unless url.is_a?(String) || url.is_a?(URI)\nFoo.get(url)","typeGuard":"valid_path = ->(p) { p.is_a?(String) || p.is_a?(URI) }","tryCatchPattern":"begin\n  Foo.get(path)\nrescue ArgumentError => e\n  raise unless e.message.include?('bad argument')\n  raise ArgumentError, \"URL was #{path.inspect} — check the variable feeding this call\"\nend","preventionTips":["Use ENV.fetch (not ENV[...]) for URL config so nil fails early with a clear message.","Call .to_s on Pathname/Addressable values before passing them in.","Assert URL presence in service constructors, not at request time."],"tags":["ruby","httparty","validation","argument-error","uri","nil-safety"],"backgroundTag":"invalid-uri-argument","analyzedSha":"8f4a09e343b94de9f934f388028ca97620c9b378","analyzedAt":"2026-08-21T19:30:42.003Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}