lostisland/faraday · critical · RuntimeError

An attempt to run a request with a Faraday::Connection witho

Error message

An attempt to run a request with a Faraday::Connection without adapter has been made.
Please set Faraday.default_adapter or provide one when initializing the connection.
For more info, check https://lostisland.github.io/faraday/usage/.

What it means

The adapter is the terminal handler that performs the actual HTTP call, and RackBuilder#ensure_adapter! raises MISSING_ADAPTER_ERROR from build_response when @adapter is nil. RackBuilder#build normally appends Faraday.default_adapter automatically unless one was set, so in practice this error means Faraday.default_adapter was nil at connection-creation time — either explicitly cleared (adapter gems' test suites do this) or set to nil by app boot code — or the adapter was never configured in a manually built stack.

Source

Thrown at lib/faraday/rack_builder.rb:230

      Env.new(request.http_method, request.body, exclusive_url,
              request.options, request.headers, connection.ssl,
              connection.parallel_manager)
    end

    private

    def raise_if_locked
      raise StackLocked, LOCK_ERR if locked?
    end

    def raise_if_adapter(klass)
      return unless klass <= Faraday::Adapter

      raise 'Adapter should be set using the `adapter` method, not `use`'
    end

    def ensure_adapter!
      raise MISSING_ADAPTER_ERROR unless @adapter
    end

    def adapter_set?
      !@adapter.nil?
    end

    def use_symbol(mod, key, ...)
      use(mod.lookup_middleware(key), ...)
    end

    def assert_index(index)
      idx = index.is_a?(Integer) ? index : @handlers.index(index)
      raise "No such handler: #{index.inspect}" unless idx

      idx
    end
  end
end

View on GitHub (pinned to b25b1b26cc)

Solutions

  1. Set an explicit adapter in the connection block: Faraday.new(url) { |b| b.adapter :net_http } — this is the documented, env-independent fix.
  2. Restore the default at boot: Faraday.default_adapter = :net_http (and ensure the adapter gem, e.g. faraday-net_http, is in the bundle for Faraday 2.x).
  3. Audit test helpers that set Faraday.default_adapter = nil and reset it in an ensure/around hook so it cannot leak into code that makes real requests.
  4. If you configure the adapter conditionally, verify conn.builder.adapter_set? before the first request and fail fast with your own message.

Example fix

# before
Faraday.default_adapter = nil # leaked from a test helper
conn = Faraday.new('https://api.example.com')
conn.get('/ping')
# => An attempt to run a request with a Faraday::Connection without adapter has been made.

# after
conn = Faraday.new('https://api.example.com') do |b|
  b.request :url_encoded
  b.adapter :net_http # explicit, immune to default_adapter state
end
conn.get('/ping')
Defensive patterns

Strategy: validation

Validate before calling

raise 'no adapter configured' unless conn.builder.adapter_set?
conn.get('/ping')

Type guard

def connection_runnable?(conn)
  conn.builder.adapter_set?
end

Try / catch

begin
  conn.get('/ping')
rescue RuntimeError => e
  raise unless e.message.include?('without adapter')
  conn.adapter :net_http # or rebuild the connection with an explicit adapter
  conn.get('/ping')
end

Prevention

When it happens

Trigger: Running Faraday.default_adapter = nil (common in specs for adapter gems) and then issuing a real request; app or gem code assigning Faraday.default_adapter = nil to 'force explicit configuration' and forgetting one connection; building a connection whose block raises before reaching the adapter line, leaving the stack half-configured; swapping adapters at runtime via builder manipulation that removes the adapter.

Common situations: Upgrading to Faraday 1.0+ where an adapter became mandatory and implicit fallbacks were removed; test environments that mutate the global Faraday.default_adapter and leak into other tests; code copied from adapter-gem specs into production; multi-tenant apps configuring Faraday defaults per-request and racing.

Related errors


AI-assisted analysis of lostisland/faraday@b25b1b26cc (2026-08-21). Data as JSON: /api/errors/f8d17274c326f07c. Report an issue: GitHub.