Class: Aspera::Cli::Hints

Inherits:
Object
  • Object
show all
Defined in:
lib/aspera/cli/hints.rb

Overview

Provide hints on errors

Class Method Summary collapse

Class Method Details

.hint_for(error, formatter) ⇒ Object

Parameters:

  • error (Exception)

    exception object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/aspera/cli/hints.rb', line 124

def hint_for(error, formatter)
  ERROR_HINTS.each do |hint|
    next unless error.is_a?(hint[:exception])
    message = error.message
    matches = hint[:match]
    matches = [matches] unless matches.is_a?(Array)
    matches.each do |m|
      Aspera.assert_values(m.class, [String, Regexp])
      case m
      when String
        next unless message.eql?(m)
      when Regexp
        next unless message.match?(m)
      else Aspera.error_unexpected_value(m)
      end
      hint[:remediation].each do |r|
        Log.log.info{"#{'HINT:'.bg_green.gray.blink.freeze} #{r}"}
      end
      break
    end
  end
end