Exception: JekyllSupport::CustomError

Inherits:
StandardError show all
Defined in:
lib/error/jekyll_custom_error.rb

Overview

Use like this: CustomError.new(:MyError, ‘blah’, ‘asdf’)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.factory(error_class_name) ⇒ Object



8
9
10
11
12
# File 'lib/error/jekyll_custom_error.rb', line 8

def self.factory(error_class_name)
  return if Object.const_defined? "::#{error_class_name}"

  Object.const_set error_class_name, Class.new(CustomError)
end

Instance Method Details

#calling_fileObject



18
19
20
21
# File 'lib/error/jekyll_custom_error.rb', line 18

def calling_file
  file_fq, _line_number, _extra = backtrace[0]&.split(':')
  file_fq
end

#error_nameObject



14
15
16
# File 'lib/error/jekyll_custom_error.rb', line 14

def error_name
  self.class.name.split('::').last
end

#html_messageObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/error/jekyll_custom_error.rb', line 24

def html_message
  shorten_backtrace
  path, line_number, _caller = backtrace[1]&.split(':')
  "    <div class='\#{error_name.snakecase}'>\n      \#{self.class} raised in \#{calling_file} while processing line \#{line_number} (after front matter) of \#{path}\n      \#{message}\n    </div>\n  END_MSG\nend\n"

#logger_messageObject



35
36
37
38
39
40
41
42
43
# File 'lib/error/jekyll_custom_error.rb', line 35

def logger_message
  shorten_backtrace
  kaller = caller(1..1).first
  path, line_number, _caller = backtrace[1]&.split(':')
  "    \#{error_name} raised in \#{kaller} while processing line \#{line_number} (after front matter) of \#{path}\n      \#{message}\n  END_MSG\nend\n"

#shorten_backtrace(backtrace_element_count = 6) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/error/jekyll_custom_error.rb', line 45

def shorten_backtrace(backtrace_element_count = 6)
  set_backtrace backtrace[0..backtrace_element_count]
  # b = backtrace[0..backtrace_element_count - 1].map do |x|
  #   x.gsub(Dir.pwd + '/', './')
  # end
  # set_backtrace b
end