lostisland / faraday

Simple, but flexible HTTP client library, with support for multiple backends.
https://lostisland.github.io/faraday
MIT License
5.71k stars 972 forks source link

Faraday 2.7.1 causes following warning: "warning: method redefined; discarding old error" #1467

Closed wuarmin closed 1 year ago

wuarmin commented 1 year ago

Hey!

Basic Info

Issue description

I get following warning

/usr/local/bundle/gems/faraday-2.7.1/lib/faraday/logging/formatter.rb:40: warning: method redefined; discarding old error
/usr/local/lib/ruby/3.1.0/forwardable.rb:229: warning: previous definition of error was here

Steps to reproduce

If I execute following code, the warning appears.

Faraday.new(url: Test::Slice[:settings].endpoint, headers: { "Content-Type" => "application/xml" }) do |conn|
  conn.use XMLMiddleware
end

Thanks and best regards

iMacTia commented 1 year ago

~Hi @wuarmin, the error is a bit strange because logging/formatter.rb should only be used if you also add the :logger middleware to your connection.~

~1. Is that the whole connection initialisation block or are you leaving out something else?~ ~2. Can you share the code for the XMLMiddleware? Is that a custom middleware?~

EDIT: Actually, I managed to reproduce this, but you need to explicitly enable warnings:

$> irb -W

3.1.2 :001 > require 'faraday'

/Users/mattiagiuffrida/.rvm/gems/ruby-3.1.2/gems/faraday-2.7.1/lib/faraday/logging/formatter.rb:40: warning: method redefined; discarding old error
/Users/mattiagiuffrida/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/forwardable.rb:229: warning: previous definition of error was here

I can see this is happening because of the changes introduced in #1460. Thanks for raising this @wuarmin 🙏 !