Exception: Toys::ContextualError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/toys/errors.rb

Overview

A wrapper exception used to provide user-oriented context for an error thrown during tool execution. Most exceptions raised during a tool run are wrapped with one of these (with the original exception set as the cause.)

Signals are not wrapped in this class. A SignalException raised by a tool propagates as itself, so that tools can intercept it and the Ruby VM can ultimately handle it. See the error_handler argument to Runner#initialize for how each is reported.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

An overall banner message

Returns:

  • (String)


97
98
99
# File 'lib/toys/errors.rb', line 97

def banner
  @banner
end

#tool_argsArray<String> (readonly)

The arguments passed to the tool that was running when the error occurred.

Returns:

  • (Array<String>)


140
141
142
# File 'lib/toys/errors.rb', line 140

def tool_args
  @tool_args
end

#tool_file_lineInteger? (readonly) Also known as: config_line

The line number in the toys tool file in which the error was detected.

Returns:

  • (Integer)

    if a tool file is found in the backtrace.

  • (nil)

    if no backtrace is available or no toys tool file could be found in it.



116
117
118
# File 'lib/toys/errors.rb', line 116

def tool_file_line
  @tool_file_line
end

#tool_file_pathString? (readonly) Also known as: config_path

The path to the toys tool file in which the error was detected.

Returns:

  • (String)

    if a tool file is found in the backtrace.

  • (nil)

    if no backtrace is available or no toys tool file could be found in it.



106
107
108
# File 'lib/toys/errors.rb', line 106

def tool_file_path
  @tool_file_path
end

#tool_nameArray<String> (readonly)

The full name of the tool that was running or being loaded when the error occurred.

Returns:

  • (Array<String>)


133
134
135
# File 'lib/toys/errors.rb', line 133

def tool_name
  @tool_name
end

#tool_verbString? (readonly)

The verb in progress when the error occurred.

Returns:

  • (String)

    should be either "loading" or "running"

  • (nil)

    if the verb is not known



125
126
127
# File 'lib/toys/errors.rb', line 125

def tool_verb
  @tool_verb
end

Instance Method Details

#root_causeException?

Returns the root cause of this error, i.e. the first cause in the chain that is not itself a ContextualError.

Returns:

  • (Exception)

    The root cause.

  • (nil)

    if this error has no cause, which happens only if it was constructed outside a rescue.



150
151
152
153
154
155
156
# File 'lib/toys/errors.rb', line 150

def root_cause
  current = cause
  while current.is_a?(ContextualError)
    current = current.cause
  end
  current
end