Skip to content

Commit

Permalink
Correctly process driver stacktrace upon error
Browse files Browse the repository at this point in the history
Related to #3683
  • Loading branch information
p0deje committed Aug 16, 2017
1 parent 3c69c54 commit f4bd516
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions rb/lib/selenium/webdriver/remote/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module WebDriver
module Remote
# @api private
class Response
STACKTRACE_KEY = 'stackTrace'.freeze

attr_reader :code, :payload
attr_writer :payload

Expand Down Expand Up @@ -73,11 +75,23 @@ def assert_ok
end

def add_backtrace(ex)
return unless value.is_a?(Hash) && value['stackTrace']
return unless error_payload.is_a?(Hash)

server_trace = error_payload[STACKTRACE_KEY] || error_payload[STACKTRACE_KEY.downcase]
return unless server_trace

server_trace = value['stackTrace']
backtrace = case server_trace
when Array
backtrace_from_remote(server_trace)
when String
server_trace.split("\n")
end

backtrace = server_trace.map do |frame|
ex.set_backtrace(backtrace + ex.backtrace)
end

def backtrace_from_remote(server_trace)
server_trace.map do |frame|
next unless frame.is_a?(Hash)

file = frame['fileName']
Expand All @@ -91,8 +105,6 @@ def add_backtrace(ex)

"[remote server] #{file}:#{line}:in `#{meth}'"
end.compact

ex.set_backtrace(backtrace + ex.backtrace)
end

def error_payload
Expand Down

0 comments on commit f4bd516

Please sign in to comment.