Skip to content

Commit

Permalink
Rename exception to exc
Browse files Browse the repository at this point in the history
Fixes collsion with Ruby's build-in method 'exception'.

https://www.honeybadger.io/blog/how-to-raise-any-object-as-a-ruby-exception/
  • Loading branch information
stgeneral committed Jul 21, 2023
1 parent da2ca83 commit 7a3b45a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions lib/auxiliary_rails/application/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ module Application
# @abstract
class Error < RuntimeError
attr_accessor :context
attr_reader :exception, :severity
attr_reader :exc, :severity

class << self
def i18n_scope
"errors.#{name.underscore}"
end

# @return [self] Wraps exception into a new Application Error object
def wrap(exception, context: {}, severity: nil)
new(exception.message, context: context, exception: exception, severity: severity)
# @return [self] Wraps exception into a new ApplicationError object
def wrap(exc, context: {}, severity: nil)
new(exc.message, context: context, exc: exc, severity: severity)
end
end

def initialize(message = nil, context: {}, exception: nil, severity: nil)
super message
def initialize(message = nil, context: {}, exc: nil, severity: nil)
super(message)

self.context = default_context.merge(context || {})
self.exception = exception
self.exc = exc
self.severity = severity&.to_sym || default_severity
end

Expand All @@ -44,7 +44,7 @@ def report

protected

attr_writer :exception, :severity
attr_writer :exc, :severity
end
end
end
6 changes: 3 additions & 3 deletions lib/auxiliary_rails/concerns/performable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ def on(status, &block)
def ensure_empty_errors!
return if errors.empty?

error!("`#{self.class}` contains errors.")
error!("'#{self.class}' contains errors.")
end

def ensure_empty_status!
return if performable_status.nil?

error!("`#{self.class}` was already executed.")
error!("'#{self.class}' was already executed.")
end

def ensure_execution!
return if performable_status.present?

error!("`#{self.class}` was not executed yet.")
error!("'#{self.class}' was not executed yet.")
end

# Sets command's status to <tt>failure</tt>.
Expand Down
4 changes: 2 additions & 2 deletions spec/sample_commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
describe '#call' do
it do
expect { cmd.call }.to raise_error AuxiliaryRails::Application::Error,
'`SampleCommands::DoubleStatusSetCommand` was already executed.'
"'SampleCommands::DoubleStatusSetCommand' was already executed."
end
end
end
Expand All @@ -40,7 +40,7 @@
describe '#call' do
it do
expect { cmd.call }.to raise_error AuxiliaryRails::Application::Error,
'`SampleCommands::SuccessWithErrorsCommand` contains errors.'
"'SampleCommands::SuccessWithErrorsCommand' contains errors."
end
end
end
Expand Down

0 comments on commit 7a3b45a

Please sign in to comment.