1
0
mirror of https://github.com/meineerde/rackstash.git synced 2026-01-31 17:27:13 +00:00

Raise ArgumentError when trying to resolve an unknown adapter URI

If we were to fall through, undefined schemes would always end up as a
file adapter. This is generally undesired since it hides the fact that
we have not found a suitable adapter. Most of the time, this will be a
configuration error which should be reported early.

If a user still wants to create a file adapter with a filename that
looks like a URI, they can create a Rackstash::Adapter::File object
manually.
This commit is contained in:
Holger Just 2018-01-22 01:05:04 +01:00
parent bdeb0534c9
commit e8bf2c31bd
2 changed files with 6 additions and 3 deletions

View File

@ -110,7 +110,9 @@ module Rackstash
scheme = uri.scheme || uri.opaque
return unless scheme
adapter_class = adapter_schemes.fetch(scheme.to_s.downcase) { return }
adapter_class = adapter_schemes.fetch(scheme.to_s.downcase) {
raise ArgumentError, "No log adapter found for URI #{uri}"
}
if adapter_class.respond_to?(:from_uri)
adapter_class.from_uri(uri)

View File

@ -261,8 +261,9 @@ describe Rackstash::Adapter do
unknown_uri = 'unknown://example.com'
expect(adapter).to_not receive(:from_uri)
expect(adapter).to receive(:new).with(unknown_uri).and_call_original
expect(described_class[unknown_uri]).to be_an Rackstash::Adapter::BaseAdapter
expect(adapter).not_to receive(:new)
expect { described_class[unknown_uri] }
.to raise_error ArgumentError, "No log adapter found for URI unknown://example.com"
end
end
end