Class: Herb::Errors::RubyParseError

Inherits:
Error
  • Object
show all
Includes:
Colors
Defined in:
lib/herb/errors.rb,
ext/herb/error_helpers.c

Constant Summary

Constants included from Colors

Colors::CLEAR_SCREEN, Colors::HIDE_CURSOR, Colors::SHOW_CURSOR

Instance Attribute Summary collapse

Attributes inherited from Error

#location, #message, #type

Instance Method Summary collapse

Methods included from Colors

bold, bright_magenta, cyan, dimmed, enabled?, fg, fg_bg, green, magenta, red, white, yellow

Methods inherited from Error

#class_name, #error_name, #to_json

Constructor Details

#initialize(type, location, message, error_message, diagnostic_id, level) ⇒ RubyParseError

: (String, Location?, String, String, String, String) -> void



386
387
388
389
390
391
# File 'lib/herb/errors.rb', line 386

def initialize(type, location, message, error_message, diagnostic_id, level)
  super(type, location, message)
  @error_message = error_message
  @diagnostic_id = diagnostic_id
  @level = level
end

Instance Attribute Details

#diagnostic_idObject (readonly)

: String?



382
383
384
# File 'lib/herb/errors.rb', line 382

def diagnostic_id
  @diagnostic_id
end

#error_messageObject (readonly)

| error_message: String?, | diagnostic_id: String?, | level: String?, | }



381
382
383
# File 'lib/herb/errors.rb', line 381

def error_message
  @error_message
end

#levelObject (readonly)

: String?



383
384
385
# File 'lib/herb/errors.rb', line 383

def level
  @level
end

Instance Method Details

#inspectObject

: () -> String



394
395
396
# File 'lib/herb/errors.rb', line 394

def inspect
  tree_inspect.rstrip.gsub(/\s+$/, "")
end

#to_hashObject

: () -> serialized_ruby_parse_error



399
400
401
402
403
404
405
# File 'lib/herb/errors.rb', line 399

def to_hash
  super.merge(
    error_message: error_message,
    diagnostic_id: diagnostic_id,
    level: level
  ) #: Herb::serialized_ruby_parse_error
end

#tree_inspect(indent: 0, depth: 0, depth_limit: 25) ⇒ Object

: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String



408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/herb/errors.rb', line 408

def tree_inspect(indent: 0, depth: 0, depth_limit: 25)
  output = +""

  output += white("@ #{bold(red(error_name))} #{dimmed("(location: #{location&.tree_inspect})\n")}")
  output += white("├── message: #{green(message.inspect)}\n")
  output += white("├── error_message: #{green(error_message.inspect)}\n")
  output += white("├── diagnostic_id: #{green(diagnostic_id.inspect)}\n")
  output += white("└── level: #{green(level.inspect)}\n")
  output += %(\n)

  output.gsub(/^/, "    " * indent)
end