Exception: Gel::UserError

Inherits:
StandardError
  • Object
show all
Includes:
ReportableError
Defined in:
lib/gel/error.rb

Overview

Base class for user-facing errors. Errors can directly include ReportableError to bypass this, but absent a specific reason, they should subclass UserError.

Prefer narrow-purpose error classes that receive context parameters over raising generic classes with pre-rendered message parameters. The former can do a better job of fully describing the problem when producing detailed CLI output, without filling real code with long message heredocs.

Define all UserError subclasses in this file. (Non-reportable errors, which describe errors in interaction between internal components, can and should be defined whereever they’re used.)

Instance Method Summary collapse

Methods included from ReportableError

#details, #exit_code

Constructor Details

#initialize(**context) ⇒ UserError

Returns a new instance of UserError.



47
48
49
50
51
# File 'lib/gel/error.rb', line 47

def initialize(**context)
  @context = context

  super message
end

Instance Method Details

#[](key) ⇒ Object



53
54
55
# File 'lib/gel/error.rb', line 53

def [](key)
  @context.fetch(key)
end

#inner_backtraceObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/gel/error.rb', line 61

def inner_backtrace
  return [] unless cause

  bt = cause.backtrace_locations
  ignored_bt = backtrace_locations

  while bt.last.to_s == ignored_bt.last.to_s
    bt.pop
    ignored_bt.pop
  end

  while bt.last.path == ignored_bt.last.path
    bt.pop
  end

  bt
end

#messageObject



57
58
59
# File 'lib/gel/error.rb', line 57

def message
  self.class.name
end