Exception: Toys::ArgParser::UsageError

Inherits:
StandardError
  • Object
show all
Defined in:
core-docs/toys/arg_parser.rb

Overview

Defined in the toys-core gem

Base representation of a usage error reported by the ArgParser.

This is normally not raised directly, but returned as an element in the #errors array. It will, however, have the normal message and backtrace attributes, along with additional fields as defined in this class, and it can be raised later if desired.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, name: nil, value: nil, suggestions: nil, skip_frames: 0) ⇒ UsageError

Create a UsageError given a message and common data

Parameters:

  • message (String)

    The basic error message.

  • name (String, nil) (defaults to: nil)

    The name of the element (normally flag or positional argument) that reported the error, or nil if there is no definite element.

  • value (String, nil) (defaults to: nil)

    The value that was rejected, or nil if not applicable.

  • suggestions (Array<String>, nil) (defaults to: nil)

    An array of suggestions from DidYouMean, or nil if not applicable.

  • skip_frames (Integer) (defaults to: 0)

    Number of call frames to skip when constructing a backtrace, in addition to this initialize call itself. Subclasses calling super from their constructor should set this to 1 to skip their own initialize frame.



38
39
40
# File 'core-docs/toys/arg_parser.rb', line 38

def initialize(message, name: nil, value: nil, suggestions: nil, skip_frames: 0)
  # Source available in the toys-core gem
end

Instance Attribute Details

#messageString (readonly)

Returns The error message, not including any suggestions.

Returns:

  • (String)

    The error message, not including any suggestions.



45
46
47
# File 'core-docs/toys/arg_parser.rb', line 45

def message
  @message
end

#nameString? (readonly)

The name of the element (normally a flag or positional argument) that reported the error.

Returns:

  • (String)

    The element name.

  • (nil)

    if there is no definite element source.



54
55
56
# File 'core-docs/toys/arg_parser.rb', line 54

def name
  @name
end

#suggestionsArray<String>? (readonly)

An array of suggestions from DidYouMean.

Returns:

  • (Array<String>)

    array of suggestions.

  • (nil)

    if suggestions are not applicable to this error.



70
71
72
# File 'core-docs/toys/arg_parser.rb', line 70

def suggestions
  @suggestions
end

#valueString? (readonly)

The value that was rejected.

Returns:

  • (String)

    the value string

  • (nil)

    if a value is not applicable to this error.



62
63
64
# File 'core-docs/toys/arg_parser.rb', line 62

def value
  @value
end

Instance Method Details

#message_with_suggestionsString Also known as: to_s

A fully formatted error message including suggestions.

Returns:

  • (String)


77
78
79
# File 'core-docs/toys/arg_parser.rb', line 77

def message_with_suggestions
  # Source available in the toys-core gem
end