Class: Console::Event::Failure
- Defined in:
- lib/console/event/failure.rb
Overview
Represents a failure of some kind, usually with an attached exception.
“‘ruby begin raise “Something went wrong!” rescue => exception Console::Event::Failure.log(“Something went wrong!”, exception) end “`
Generally, you should use the Console.error method to log failures, as it will automatically create a failure event for you.
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
Class Method Summary collapse
-
.default_root ⇒ Object
For the purpose of efficiently formatting backtraces, we need to know the root directory of the project.
-
.for(exception) ⇒ Object
Create a new failure event for the given exception.
-
.log(subject, exception, **options) ⇒ Object
Log a failure event with the given exception.
Instance Method Summary collapse
-
#emit(*arguments, **options) ⇒ Object
Log the failure event.
-
#initialize(exception, root = self.class.default_root) ⇒ Failure
constructor
Create a new failure event for the given exception.
- #The exception which caused the failure.=(exceptionwhichcausedthefailure. = (value)) ⇒ Object
-
#to_hash ⇒ Object
Convert the failure event to a hash.
Methods inherited from Generic
Constructor Details
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
50 51 52 |
# File 'lib/console/event/failure.rb', line 50 def exception @exception end |
Class Method Details
.default_root ⇒ Object
For the purpose of efficiently formatting backtraces, we need to know the root directory of the project.
27 28 29 30 31 |
# File 'lib/console/event/failure.rb', line 27 def self.default_root Dir.getwd rescue # e.g. Errno::EMFILE nil end |
.for(exception) ⇒ Object
Create a new failure event for the given exception.
36 37 38 |
# File 'lib/console/event/failure.rb', line 36 def self.for(exception) self.new(exception, self.default_root) end |
Instance Method Details
#emit(*arguments, **options) ⇒ Object
Log the failure event.
76 77 78 79 80 |
# File 'lib/console/event/failure.rb', line 76 def emit(*arguments, **) [:severity] ||= :error super end |
#The exception which caused the failure.=(exceptionwhichcausedthefailure. = (value)) ⇒ Object
50 |
# File 'lib/console/event/failure.rb', line 50 attr_reader :exception |
#to_hash ⇒ Object
Convert the failure event to a hash.
64 65 66 67 68 69 70 |
# File 'lib/console/event/failure.rb', line 64 def to_hash Hash.new.tap do |hash| hash[:type] = :failure hash[:root] = @root if @root extract(@exception, hash) end end |