Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite recursion and NameError on load when running with -rdebug #1203

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/faraday.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ def respond_to_missing?(symbol, include_private = false)
# Internal: Proxies method calls on the Faraday constant to
# .default_connection.
def method_missing(name, *args, &block)
# When running under debugger with a breakpoint set,
# self.to_str is called repeatedly during module load,
# including the time before the default_connection getter below is loaded
if name == :default_connection
return nil
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style opinion: These guards would look easier to read as a "suffix if", like

return nil if name == :default_connection

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I don't really have a preference here. I first tried name == :default_connection && return nil but that turned out to be invalid syntax ☹️


if default_connection.respond_to?(name)
default_connection.send(name, *args, &block)
else
Expand All @@ -135,6 +142,14 @@ def method_missing(name, *args, &block)
# access the Faraday constant directly, such as
# <code>Faraday.get "https://faraday.com"</code>.
def self.default_connection
# When running under debugger with a breakpoint set,
# self.to_str is called repeatedly during module load,
# including the time after this getter is loaded but
# before the libs delay-loading below fires
unless const_defined?(:Connection)
return nil
end

@default_connection ||= Connection.new(default_connection_options)
end

Expand Down