Exception: AppleBot::AppleBotError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/applebot/error.rb,
lib/applebot/error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error, output = [], message = nil) ⇒ AppleBotError

Returns a new instance of AppleBotError.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/applebot/error.rb', line 7

def initialize(error, output = [], message = nil)
  super(self.class.message)
  output ||= []
  output = output.map(&:strip).reject(&:blank?)
  @html = output.select {|n|
    is_debug_html?(n)
  }.map { |s|
    JSON.parse(s)['html']
  }.first

  @output = output.reject {|n|
    is_debug_html?(n)
  }

  full_backtrace = (@output.map { |o|
    "#{o}:in `AppleBot'"
  } + error.backtrace).compact
  set_backtrace(full_backtrace)
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



5
6
7
# File 'lib/applebot/error.rb', line 5

def html
  @html
end

#outputObject (readonly)

Returns the value of attribute output.



5
6
7
# File 'lib/applebot/error.rb', line 5

def output
  @output
end

Class Method Details

.for_output(output = []) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/applebot/error.rb', line 68

def self.for_output(output = [])
  output ||= []

  error_class = nil

  output.each { |line|
    MESSAGE_FRAGMENT_TO_ERROR.each { |message, klass|
      if line.include?(message)
        error_class = klass
        break
      end
    }
    break if error_class
  }
  error_class ||= AppleBotError

  begin
    # capture the Ruby-level stack trace
    raise StandardError
  rescue Exception => e
    error_class.new(e, output)
  end
end

.testObject



92
93
94
# File 'lib/applebot/error.rb', line 92

def self.test
  raise for_output(["something", "happened"])
end

Instance Method Details

#is_debug_html?(line) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/applebot/error.rb', line 27

def is_debug_html?(line)
  line.include?('"event":"debug_html"')
end