Skip to content

Commit

Permalink
Bail out before trying to extend Backend::Interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Aug 25, 2024
1 parent 8d60b7a commit 5e56726
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/metrics/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ def self.require_backend(env = ENV)
require(backend)
rescue LoadError => error
::Console::Event::Failure.for(error).emit(self, "Unable to load metrics backend!", backend: backend, severity: :warn)

return false
end

Metrics.extend(Backend::Interface)

return true
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion test/metrics/backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
include_context Sus::Fixtures::Console::CapturedLogger

it "logs a warning if backend cannot be loaded" do
subject.require_backend({"METRICS_BACKEND" => "metrics/backend/missing"})
expect(
subject.require_backend({"METRICS_BACKEND" => "metrics/backend/missing"})
).to be == false

expect_console.to have_logged(
severity: be == :warn,
Expand Down

0 comments on commit 5e56726

Please sign in to comment.