Repository navigation
Description
Running into this error after upgrading from 2.13.1 to 2.13.2
Seems related to this: https://github.com/lostisland/faraday/pull/1628/files#diff-c5f031a4be2bbda4d7befb7c1604ffee77d3bc86038f280aca9b14f1fc00350e
App code:
MyClient.new.create_user(sign_up_data)
class MyClient
attr_reader :base_url
def initialize(base_url)
@base_url = base_url
end
def create_user(params)
connection.post('registrations', params)
end
def connection
@connection ||= build_connection
end
private
# :reek:FeatureEnvy, :reek:TooManyStatements
def build_connection
Faraday.new(options) do |config|
config.use Signature
config.request :json
config.response :json, preserve_raw: true
config.response :raise_error
config.response :logger, Rails.logger, { bodies: true, headers: true, log_level: :debug }
end
end
def options
{
request: {
open_timeout: 5,
read_timeout: 15,
write_timeout: 15
},
url: base_url
}
end
endStacktrace:
KeyError: key not found: :status
0) RegistrationsController POST reate when Root Central has an error when Root Central has a non-JSON error renders the registration page with a default message
Failure/Error: RootSDK::RootCentral::Client.new.create_user(sign_up_data)
KeyError:
key not found: :status
> /Users/root/.rvm/gems/ruby-3.2.8/gems/faraday-2.13.2/lib/faraday/error.rb:85:in 'fetch'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/faraday-2.13.2/lib/faraday/error.rb:85:in 'exc_msg_and_response'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/faraday-2.13.2/lib/faraday/error.rb:73:in 'exc_msg_and_response!'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/faraday-2.13.2/lib/faraday/error.rb:12:in 'initialize'
> ./app/controllers/registrations_controller.rb:11:in 'create'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/ddtrace-1.23.3/lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb:105:in 'process_action'
> ./app/controllers/application_controller.rb:15:in 'set_time_zone'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/turbo-rails-2.0.12/lib/turbo-rails.rb:24:in 'with_request_id'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/turbo-rails-2.0.12/app/controllers/concerns/turbo/request_id_tracking.rb:10:in 'turbo_tracking_request_id'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/react-rails-2.7.1/lib/react/rails/controller_lifecycle.rb:31:in 'use_react_component_helper'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/audited-5.8.0/lib/audited/sweeper.rb:16:in 'around'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/audited-5.8.0/lib/audited/sweeper.rb:16:in 'around'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/actiontext-7.0.8.7/lib/action_text/rendering.rb:20:in 'with_renderer'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/actiontext-7.0.8.7/lib/action_text/engine.rb:69:in 'block (4 levels) in <class:Engine>'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/omniauth-2.1.3/lib/omniauth/strategy.rb:202:in 'call!'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/omniauth-2.1.3/lib/omniauth/strategy.rb:169:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/rack-attack-6.7.0/lib/rack/attack.rb:127:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/exception_notification-4.6.0/lib/exception_notification/rack.rb:49:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/warden-1.2.9/lib/warden/manager.rb:36:in 'block in call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/warden-1.2.9/lib/warden/manager.rb:34:in 'catch'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/warden-1.2.9/lib/warden/manager.rb:34:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/rack-2.2.17/lib/rack/tempfile_reaper.rb:15:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/rack-2.2.17/lib/rack/etag.rb:27:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/rack-2.2.17/lib/rack/conditional_get.rb:40:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/rack-2.2.17/lib/rack/head.rb:12:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/rack-2.2.17/lib/rack/session/abstract/id.rb:266:in 'context'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/rack-2.2.17/lib/rack/session/abstract/id.rb:260:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/ddtrace-1.23.3/lib/datadog/tracing/contrib/rails/middlewares.rb:19:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/railties-7.0.8.7/lib/rails/rack/logger.rb:40:in 'call_app'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/railties-7.0.8.7/lib/rails/rack/logger.rb:25:in 'block in call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/semantic_logger-4.16.1/lib/semantic_logger/base.rb:190:in 'block in tagged'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/semantic_logger-4.16.1/lib/semantic_logger/semantic_logger.rb:356:in 'tagged'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/semantic_logger-4.16.1/lib/semantic_logger/base.rb:202:in 'tagged'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/railties-7.0.8.7/lib/rails/rack/logger.rb:25:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/rack-2.2.17/lib/rack/method_override.rb:24:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/rack-2.2.17/lib/rack/runtime.rb:22:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/rack-2.2.17/lib/rack/sendfile.rb:110:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/ddtrace-1.23.3/lib/datadog/tracing/contrib/rack/middlewares.rb:109:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/railties-7.0.8.7/lib/rails/engine.rb:530:in 'call'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/rack-test-2.2.0/lib/rack/test.rb:360:in 'process_request'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/rack-test-2.2.0/lib/rack/test.rb:153:in 'request'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/rails-controller-testing-1.0.5/lib/rails/controller/testing/integration.rb:16:in 'block (2 levels) in <module:Integration>'
> ./spec/requests/registrations_controller_spec.rb:21:in 'block (3 levels) in <main>'
> ./spec/requests/registrations_controller_spec.rb:89:in 'block (5 levels) in <main>'
> ./spec/rails_helper.rb:99:in 'block (3 levels) in <top (required)>'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/database_cleaner-core-2.0.1/lib/database_cleaner/strategy.rb:30:in 'cleaning'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/database_cleaner-core-2.0.1/lib/database_cleaner/cleaners.rb:34:in 'block (2 levels) in cleaning'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/database_cleaner-core-2.0.1/lib/database_cleaner/cleaners.rb:35:in 'cleaning'
> ./spec/rails_helper.rb:99:in 'block (2 levels) in <top (required)>'
> /Users/root/.rvm/gems/ruby-3.2.8/gems/webmock-3.25.1/lib/webmock/rspec.rb:39:in 'block (2 levels) in <main>'
Metadata
Metadata
Assignees
Labels
No labels
Activity
iMacTia commentedon Jul 15, 2025
Thank you for raising this @Vpatel1093, and sorry you bumped into it.
It's really strange that the response object doesn't have any
statusproperty.Does this happen in production or during tests?
Also, I see you have the
loggermiddleware in your configuration, could you check if your logs have anything to show about the response? (it should, as being at the bottom of the config it should log the response BEFORE theraise_errormiddleware raises this exception)derekharmel commentedon Jul 15, 2025
I'm seeing a similar problem that I believe is likely caused by @Vpatel1093's issue.
We're using v2.0.1 the zendesk_api gem which is using Faraday. Since the updating Faraday to 2.13.2, we're experiencing a problem in that library's error handling code.
Stacktrace:
Relevant code from the zendesk_api library in the stacktrace above:
https://github.com/zendesk/zendesk_api_client_rb/blob/v2.0.1/lib/zendesk_api/error.rb#L22
https://github.com/zendesk/zendesk_api_client_rb/blob/v2.0.1/lib/zendesk_api/middleware/response/raise_error.rb#L18
I did some debugging via monkeypatching in the zendesk_api gem with the following:
The
puts 0:printed0: [#<Faraday::Env @method=:post @request_body="{.... Whereas, theputs 1:printed1: nil. Therefore something insuperis causing the problem and if you trace through the code in the links above the cause has to be inFaraday::ClientErrorand thereforeFaraday::Error. I suspect the recent changes toFaraday::Error#exc_msg_and_responseare the problem, but haven't figured out what's happening.Vpatel1093 commentedon Jul 15, 2025
@iMacTia This was during tests, we have 2.13.1 in production still. I copied everything that rspec printed out here
derekharmel commentedon Jul 15, 2025
Just following up to confirm that rolling back to 2.13.1 resolved my problem.
iMacTia commentedon Jul 21, 2025
OK sorry I didn't have time to look again at this until today, but I think the issue might be that
responsecould be aStructtoo. I'll validate this and see if I can push a fixiMacTia commentedon Jul 21, 2025
Allright, I could confirm that
Structdoes indeed respond to#each_keylikeHash, meaning the newis_a?(Hash)check is incomplete, I'll address that and ask you both to test if that's OK πFix type assumption in `Faraday::Error`
iMacTia commentedon Jul 21, 2025
I've got a PR (#1630) ready to address this.
@derekharmel @Vpatel1093 would you have some time to pull the PR branch into your project and test if it solves the problem?
a-lavis commentedon Jul 21, 2025
@iMacTia I was running into the same issue with the
zendesk_apigem - when I changed my gemfile to:that seems to have fixed the bug! thanks for working on the fix!
iMacTia commentedon Jul 22, 2025
Fantastic! Thank you for confirming @a-lavis, I'll merge and release π
Fix type assumption in `Faraday::Error` (#1630)
NikosVlagoidis commentedon Jul 24, 2025
After upgrading to
Faraday 2.13.3, callingclient.users.find(id: 'non_existing_id')withzendesk_apithrows:KeyError: key not found: :methodRoot Cause
When the API returns 400 Bad Request, exc.request here is a Faraday::RequestOptions instance that doesn't have a
methodmethod, but the error handling code expects it. In that case it should probably beexc.methodEnvironment
Faraday: 2.13.3
zendesk_api: 3.1.1
iMacTia commentedon Jul 24, 2025
Ah thank you for raising this @NikosVlagoidis, I didn't have time to write proper tests and was focusing more on getting the error fixed. It looks like there are wider differences between the
Hashand theFaraday::Envbehaviour than I originally thought. I'll see if I can get this addressed properlyiMacTia commentedon Jul 24, 2025
This should now be properly addressed (and tested) in #1633.
PR is awaiting review, but @NikosVlagoidis if you could give it a try in the meantime that would be great π
NikosVlagoidis commentedon Jul 25, 2025
Hello, we are now getting
NoMethodError: undefined method 'method=' for an instance of Faraday::RequestOptions, that comes from this line.As mentioned in my previous comment, the
env.requesthere is present. But it's an instance of Faraday::RequestOptions which doesn't define amethod.We need to check the type of
env.request, which is either a Hash (not sure about this one) or an instance ofFaraday::RequestOptions, to decide how to extract the HTTP verb and URL.iMacTia commentedon Jul 25, 2025
Uh I didn't remember we override
#fetchinOptions, really glad you spot this additional issue before release!env.optionsshould always return aFaraday::RequestOptions, so now that you mention it I believe we don't need to deal with this scenario. I'll update the codeiMacTia commentedon Jul 25, 2025
@NikosVlagoidis I simplified things a little so we don't even care about
requestif we're dealing withFaraday::Envanymore. Not sure why I went to the trouble of doing all that π.CI is green again, but as usual I'd appreciate if you could give it a go with all your project dependencies and test the integration with the Zendesk gem π
NikosVlagoidis commentedon Jul 25, 2025
@iMacTia I can confirm it works as expected now. Thanks for taking care of it!
iMacTia commentedon Jul 25, 2025
Thank you again for reporting and assisting with tests π !
I'll merge the PR and cut a new release π