class Console::Event::Failure

“‘
Console::Event::Failure.for(exception).emit(self)
“`ruby
Represents a failure event.

def self.default_root

def self.default_root
	Dir.getwd
rescue # e.g. Errno::EMFILE
	nil
end

def self.for(exception)

def self.for(exception)
	self.new(exception, self.default_root)
end

def self.log(subject, exception, **options)

def self.log(subject, exception, **options)
	Console.error(subject, **self.for(exception).to_hash, **options)
end

def emit(*arguments, **options)

def emit(*arguments, **options)
	options[:severity] ||= :error
	
	super
end

def extract(exception, hash)

def extract(exception, hash)
	hash[:class] = exception.class.name
	
	if exception.respond_to?(:detailed_message)
		message = exception.detailed_message
		
		# We want to remove the trailling exception class as we format it differently:
		message.sub!(/\s*\(.*?\)$/, "")
		
		hash[:message] = message
	else
		hash[:message] = exception.message
	end
	
	hash[:backtrace] = exception.backtrace
	
	if cause = exception.cause
		hash[:cause] = Hash.new.tap do |cause_hash|
			extract(cause, cause_hash)
		end
	end
end

def initialize(exception, root = Dir.getwd)

def initialize(exception, root = Dir.getwd)
	@exception = exception
	@root = root
end

def to_hash

def to_hash
	Hash.new.tap do |hash|
		hash[:type] = :failure
		hash[:root] = @root if @root
		extract(@exception, hash)
	end
end