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



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/aspera/cli/hints.rb', line 56

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
      remediation = hint[:remediation]
      remediation = [remediation] unless remediation.is_a?(Array)
      remediation.each{|r|formatter.display_message(:error, "#{Formatter::HINT_FLASH} #{r}")}
      break
    end
  end
end