Exception: Luoma::DetailedLuomaError
- Inherits:
-
LuomaError
- Object
- StandardError
- LuomaError
- Luoma::DetailedLuomaError
- Defined in:
- lib/luoma/errors.rb,
sig/luoma/errors.rbs
Direct Known Subclasses
DisabledTagError, FilterArgumentError, FilterNotFoundError, NoSuchTemplateError, PredicateNotFoundError, TemplateInheritanceError, TemplateSyntaxError, TemplateTypeError, UndefinedVariableError
Instance Attribute Summary collapse
-
#source ⇒ String
Returns the value of attribute source.
-
#template_name ⇒ String
Returns the value of attribute template_name.
-
#token ⇒ t_token
Returns the value of attribute token.
Instance Method Summary collapse
- #detailed_message(highlight: true, **kwargs) ⇒ String
- #error_context(source, index) ⇒ [Integer, Integer, String]
-
#initialize(message, token, source, template_name) ⇒ DetailedLuomaError
constructor
A new instance of DetailedLuomaError.
Constructor Details
#initialize(message, token, source, template_name) ⇒ DetailedLuomaError
Returns a new instance of DetailedLuomaError.
11 12 13 14 15 16 |
# File 'lib/luoma/errors.rb', line 11 def initialize(, token, source, template_name) super() @token = token @source = source @template_name = template_name end |
Instance Attribute Details
#source ⇒ String
Returns the value of attribute source.
9 10 11 |
# File 'lib/luoma/errors.rb', line 9 def source @source end |
#template_name ⇒ String
Returns the value of attribute template_name.
9 10 11 |
# File 'lib/luoma/errors.rb', line 9 def template_name @template_name end |
#token ⇒ t_token
Returns the value of attribute token.
9 10 11 |
# File 'lib/luoma/errors.rb', line 9 def token @token end |
Instance Method Details
#detailed_message(highlight: true, **kwargs) ⇒ String
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/luoma/errors.rb', line 18 def (highlight: true, **kwargs) value = Luoma.get_token_value(@token, @source) line, col, current_line = error_context(@source, @token[1]) name_and_position = if @template_name.empty? "#{current_line.inspect}:#{line}:#{col}" else "#{@template_name}:#{line}:#{col}" end pad = " " * line.to_s.length pointer_size = value.empty? ? 1 : value.length pointer = (" " * (col - 1)) + ("^" * pointer_size) <<~MESSAGE.strip #{self.class}: #{} #{pad} -> #{name_and_position} #{pad} | #{line} | #{current_line} #{pad} | #{pointer} #{highlight ? "\e[1m#{}\e[0m" : } MESSAGE end |
#error_context(source, index) ⇒ [Integer, Integer, String]
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/luoma/errors.rb', line 43 def error_context(source, index) lines = source.lines cumulative_length = 0 target_line_index = -1 lines.each_with_index do |line, i| cumulative_length += line.length next unless index < cumulative_length target_line_index = i line_number = target_line_index + 1 column_number = index - (cumulative_length - lines[target_line_index].length) + 1 return [line_number, column_number, lines[target_line_index].rstrip] end # Point to end of file line_number = lines.length column_number = lines.last.length + 1 [line_number, column_number, lines.last.rstrip] end |