Class: Awestruct::ExceptionHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/awestruct/util/exception_helper.rb

Constant Summary collapse

EXITCODES =
{:generation_error => 125, :success => 0}
@@failed =
false

Class Method Summary collapse

Class Method Details

.build_failed?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/awestruct/util/exception_helper.rb', line 31

def self.build_failed?
  return @@failed
end

.html_error_report(exception, relative_source_path) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/awestruct/util/exception_helper.rb', line 35

def self.html_error_report exception, relative_source_path
  mark_failed
  "<h1>#{exception.message}</h1>
<h2>Rendering file #{relative_source_path} resulted in a failure.</h2>
<p>Line: #{(exception.respond_to? :line) ? exception.line : 'unknown'}</p>
<p>Backtrace:</p>
<pre>#{exception.backtrace.join "\n"}</pre>"
end

.log_backtrace(exception) ⇒ Object



17
18
19
# File 'lib/awestruct/util/exception_helper.rb', line 17

def self.log_backtrace exception
  $LOG.error "#{exception.backtrace.join("\n")}"
end

.log_building_error(exception, relative_source_path) ⇒ Object



21
22
23
24
25
# File 'lib/awestruct/util/exception_helper.rb', line 21

def self.log_building_error exception, relative_source_path
  $LOG.error "While processing file #{relative_source_path}"
  self.log_error exception
  self.log_backtrace exception
end

.log_error(exception) ⇒ Object



12
13
14
15
# File 'lib/awestruct/util/exception_helper.rb', line 12

def self.log_error exception
  mark_failed
  $LOG.error "An error occurred: #{exception.message}"
end

.log_message(message) ⇒ Object



8
9
10
# File 'lib/awestruct/util/exception_helper.rb', line 8

def self.log_message message
  $LOG.error message
end

.mark_failedObject



27
28
29
# File 'lib/awestruct/util/exception_helper.rb', line 27

def self.mark_failed
  @@failed = true
end