-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add granular errors for Elasticsearch patch
With this change, the granular errors normally raised by Elasticsearch will be preserved. Previously we were discarding the granular error information raised by the Elasticsearch client and simply raising an "Error" subclass. Now we raise a Faulty error which is always a subclass of whichever error was raised by Elasticsearch itself. To do this, we add support for procs in the new error_mapper option for circuits. This allows us to individually map the errors returned by Elasticsearch. Add Faulty::Deprecation for deprecation notification DEPRECATIONS: - The error_module option is deprecated. Patches should use the error_module option instead. The option will be removed in 0.9
- Loading branch information
1 parent
a5a3631
commit 4df6e27
Showing
12 changed files
with
218 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
class Faulty | ||
# Support deprecating Faulty features | ||
module Deprecation | ||
class << self | ||
# Call to raise errors instead of logging warnings for Faulty deprecations | ||
def raise_errors!(enabled = true) | ||
@raise_errors = (enabled == true) | ||
end | ||
|
||
def silenced | ||
@silence = true | ||
yield | ||
ensure | ||
@silence = false | ||
end | ||
|
||
# @private | ||
def method(klass, name, note: nil, sunset: nil) | ||
deprecate("#{klass}##{name}", note: note, sunset: sunset) | ||
end | ||
|
||
# @private | ||
def deprecate(subject, note: nil, sunset: nil) | ||
return if @silence | ||
|
||
message = "#{subject} is deprecated" | ||
message += " and will be removed in #{sunset}" if sunset | ||
message += " (#{note})" if note | ||
raise DeprecationError, message if @raise_errors | ||
|
||
Kernel.warn("DEPRECATION: #{message}") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Faulty::Deprecation do | ||
it 'prints note and sunset version' do | ||
expect(Kernel).to receive(:warn) | ||
.with('DEPRECATION: foo is deprecated and will be removed in 1.0 (Use bar)') | ||
described_class.deprecate(:foo, note: 'Use bar', sunset: '1.0') | ||
end | ||
|
||
it 'prints only subject' do | ||
expect(Kernel).to receive(:warn) | ||
.with('DEPRECATION: blah is deprecated') | ||
described_class.deprecate('blah') | ||
end | ||
|
||
it 'prints method deprecation' do | ||
expect(Kernel).to receive(:warn) | ||
.with('DEPRECATION: Faulty::Circuit#foo is deprecated and will be removed in 1.0 (Use bar)') | ||
described_class.method(Faulty::Circuit, :foo, note: 'Use bar', sunset: '1.0') | ||
end | ||
|
||
context 'with raise_errors!' do | ||
before { described_class.raise_errors! } | ||
|
||
after { described_class.raise_errors!(false) } | ||
|
||
it 'raises DeprecationError' do | ||
expect { described_class.deprecate('blah') } | ||
.to raise_error(Faulty::DeprecationError, 'blah is deprecated') | ||
end | ||
end | ||
|
||
context 'when silenced' do | ||
it 'does not surface deprecations' do | ||
expect(Kernel).not_to receive(:warn) | ||
described_class.silenced do | ||
described_class.deprecate('blah') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.