lostisland / faraday

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

Not working faraday-1.10.0 with faraday-patron-1.0.0 #1431

Closed tadao closed 2 years ago

tadao commented 2 years ago

Basic Info

Issue description

I got this error, missing dependency for Faraday::Adapter::Patron: cannot load such file -- patron (RuntimeError).

Steps to reproduce

require 'faraday'

conn = Faraday.new("") do |builder|
  builder.adapter :patron
end

conn.get("https://google.com")

Gemfile

# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

gem "faraday", "~> 1.10"
gem "faraday-patron", "~> 1"

How can I fix this error?

olleolleolle commented 2 years ago

@tadao What would happen if you added gem "patron" to your Gemfile?

tadao commented 2 years ago

@tadao What would happen if you added gem "patron" to your Gemfile?

OMG. I added gem "patron" and then everything worked out!! perfect!! Thank you very much :)

iMacTia commented 2 years ago

@tadao to add to @olleolleolle, faraday 1.10 already has faraday-patron as a dependency, which in turns has patron as a dependency, meaning you should already have all of them in your bundle with just gem 'faraday', '~> 1.10' in your Gemfile.

The issue you're having is that patron is not automatically required by faraday-patron 1.0 (I need to check if this is intentional or not 🤔, you might have found a bug there). You should be able to remove both faraday-patron and patron from your Gemfile, and then simply add require 'patron' shortly after you require 'faraday' in your app

iMacTia commented 2 years ago

Ah, it seems like the problem is we're including patron as a dependency in faraday-patron, which makes sense for v2, but not for v1 when adapter dependencies were manually added where needed.

@olleolleolle suggestion to add gem "patron" to the Gemfile is the correct one then. You should still be able to remove faraday-patron from the Gemfile though and things should still work 👍

tadao commented 2 years ago

@iMacTia Thank you for your reply.

we're including patron as a dependency in faraday-patron, which makes sense for v2, but not for v1 when adapter dependencies were manually added where needed.

I got it. I found that if there is a faraday dependency on another gem, it will give me an error if I don't include the gem patron. Especially with RoR projects, this problem can occur. I currently have had this problem.

Thanks to the immediate response I received, I was able to solve the problem right away. I really appreciate it.