Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDP: support Runtime.getExceptionDetails method #840

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 48 additions & 31 deletions lib/debug/server_cdp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,8 @@ def process_protocol_request req
code: INVALID_PARAMS,
message: "'callFrameId' is an invalid"
end
when 'Runtime.getProperties'
oid = req.dig('params', 'objectId')
when 'Runtime.getProperties', 'Runtime.getExceptionDetails'
oid = req.dig('params', 'objectId') || req.dig('params', 'errorObjectId')
if ref = @obj_map[oid]
case ref[0]
when 'local'
Expand Down Expand Up @@ -759,6 +759,8 @@ def process_protocol_request req
return :retry
when 'properties'
request_tc [:cdp, :properties, req, oid]
when 'exception'
request_tc [:cdp, :exception, req, oid]
when 'script'
# TODO: Support script and global types
@ui.respond req, result: []
Expand Down Expand Up @@ -895,6 +897,9 @@ def cdp_event args
frame[:scriptId] = s_id
end
}
if oid = exc[:exception][:objectId]
@obj_map[oid] = ['exception']
end
end
rs = result.dig(:response, :result)
[rs].each{|obj|
Expand Down Expand Up @@ -932,6 +937,8 @@ def cdp_event args
}
}
@ui.respond req, **result
when :exception
@ui.respond req, **result
end
end
end
Expand Down Expand Up @@ -1051,35 +1058,7 @@ def process_cdp args
result = current_frame.binding.eval(expr.to_s, '(DEBUG CONSOLE)')
rescue Exception => e
result = e
b = result.backtrace.map{|e| " #{e}\n"}
frames = [
{
columnNumber: 0,
functionName: 'eval',
lineNumber: 0,
url: ''
}
]
e.backtrace_locations&.each do |loc|
break if loc.path == __FILE__
path = loc.absolute_path || loc.path
frames << {
columnNumber: 0,
functionName: loc.base_label,
lineNumber: loc.lineno - 1,
url: path
}
end
res[:exceptionDetails] = {
exceptionId: 1,
text: 'Uncaught',
lineNumber: 0,
columnNumber: 0,
exception: evaluate_result(result),
stackTrace: {
callFrames: frames
}
}
res[:exceptionDetails] = exceptionDetails(e, 'Uncaught')
ensure
output = $stdout.string
$stdout = orig_stdout
Expand Down Expand Up @@ -1158,9 +1137,47 @@ def process_cdp args
prop += [internalProperty('#class', M_CLASS.bind_call(obj))]
end
event! :cdp_result, :properties, req, result: result, internalProperties: prop
when :exception
oid = args.shift
exc = nil
if obj = @obj_map[oid]
exc = exceptionDetails obj, obj.to_s
end
event! :cdp_result, :exception, req, exceptionDetails: exc
end
end

def exceptionDetails exc, text
frames = [
{
columnNumber: 0,
functionName: 'eval',
lineNumber: 0,
url: ''
}
]
exc.backtrace_locations&.each do |loc|
break if loc.path == __FILE__
path = loc.absolute_path || loc.path
frames << {
columnNumber: 0,
functionName: loc.base_label,
lineNumber: loc.lineno - 1,
url: path
}
end
{
exceptionId: 1,
text: text,
lineNumber: 0,
columnNumber: 0,
exception: evaluate_result(exc),
stackTrace: {
callFrames: frames
}
}
end

def search_const b, expr
cs = expr.delete_prefix('::').split('::')
[Object, *b.eval('::Module.nesting')].reverse_each{|mod|
Expand Down