Skip to content

Commit aaa10c9

Browse files
committed
started getting exceptions working
1 parent 5887348 commit aaa10c9

1 file changed

Lines changed: 55 additions & 51 deletions

File tree

‎v4-cokapi/backends/ruby/pg_logger.rb‎

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class MaxStepsException < RuntimeError
7575
# certain limit (e.g., 300 executed steps), issue this special event
7676
# at the end. fill in the exception_msg field to say something like
7777
# "(stopped after N steps to prevent possible infinite loop)"
78-
raise MaxStepsException if n_steps >= MAX_STEPS # TODO: xxx
78+
raise MaxStepsException if n_steps >= MAX_STEPS
7979

8080
STDERR.puts '---'
8181
STDERR.puts [tp.event, tp.lineno, tp.path, tp.defined_class, tp.method_id].inspect
@@ -88,11 +88,6 @@ class MaxStepsException < RuntimeError
8888
retval = tp.return_value.inspect # TODO: make into true objects later
8989
end
9090

91-
if tp.event == :raise
92-
STDERR.print 'RAISE!!! '
93-
STDERR.puts tp.raised_exception.inspect
94-
end
95-
9691
evt_type = case tp.event
9792
when :line then "step_line"
9893
when :call, :b_call, :class then "call"
@@ -145,6 +140,12 @@ class MaxStepsException < RuntimeError
145140
end
146141

147142

143+
if tp.event == :raise
144+
STDERR.print 'RAISE!!! '
145+
STDERR.puts tp.raised_exception.inspect
146+
entry['exception_msg'] = tp.raised_exception.inspect # TODO: make into true objects later
147+
end
148+
148149
# adapted from https://github.com/ko1/pretty_backtrace/blob/master/lib/pretty_backtrace.rb
149150
def self.iseq_local_variables iseq
150151
_,_,_,_,arg_info,name,path,a_path,_,type,lvs, * = iseq.to_a
@@ -162,56 +163,60 @@ def self.iseq_local_variables iseq
162163
break if /in `eval'/ =~ loc.to_s
163164

164165
stack_entry = {}
165-
stack << stack_entry
166-
167166
stack_entry['is_highlighted'] = false # set the last entry to true later
168167

169168
iseq = dc.frame_iseq(i)
170-
raise "WTF WTF WTF?!?" unless iseq
171-
172-
b = dc.frame_binding(i)
169+
if !iseq
170+
# if you're, say, in a built-in operator like :/ (division)
171+
# totally punt since we can't get any useful info
172+
next
173+
else
174+
b = dc.frame_binding(i)
175+
176+
# frame_id field exists only in my hacked Ruby interpreter!
177+
canonical_fid = ordered_frame_ids[b.frame_id]
178+
if !canonical_fid
179+
canonical_fid = cur_frame_id
180+
ordered_frame_ids[b.frame_id] = cur_frame_id
181+
cur_frame_id += 1
182+
end
173183

174-
# frame_id field exists only in my hacked Ruby interpreter!
175-
canonical_fid = ordered_frame_ids[b.frame_id]
176-
if !canonical_fid
177-
canonical_fid = cur_frame_id
178-
ordered_frame_ids[b.frame_id] = cur_frame_id
179-
cur_frame_id += 1
184+
boc = binding.of_caller(i+1) # need +1 for some reason
185+
186+
# hacky since we use of_caller -- make sure it looks legit
187+
STDERR.print 'frame_description: '
188+
STDERR.puts boc.frame_description
189+
STDERR.print 'frame_type: '
190+
STDERR.puts boc.frame_type # 'eval', 'method', 'block'
191+
192+
stack_entry['func_name'] = boc.frame_description # TODO: integrate 'frame_type' too?
193+
194+
STDERR.print 'frame_id: '
195+
STDERR.puts canonical_fid
196+
stack_entry['frame_id'] = canonical_fid
197+
stack_entry['unique_hash'] = stack_entry['func_name'] + '_f' + stack_entry['frame_id'].to_s
198+
199+
# unsupported features
200+
stack_entry['is_parent'] = false
201+
stack_entry['is_zombie'] = false
202+
stack_entry['parent_frame_id_list'] = []
203+
204+
lvs = iseq_local_variables(iseq)
205+
lvs_val = lvs.inject({}){|r, lv|
206+
begin
207+
v = b.local_variable_get(lv).inspect # TODO: make into true objects later
208+
r[lv] = v
209+
rescue NameError
210+
# ignore
211+
end
212+
r
213+
}
214+
215+
stack_entry['ordered_varnames'] = lvs.map { |e| e.to_s }
216+
stack_entry['encoded_locals'] = lvs_val
180217
end
181218

182-
boc = binding.of_caller(i+1) # need +1 for some reason
183-
184-
# hacky since we use of_caller -- make sure it looks legit
185-
STDERR.print 'frame_description: '
186-
STDERR.puts boc.frame_description
187-
STDERR.print 'frame_type: '
188-
STDERR.puts boc.frame_type # 'eval', 'method', 'block'
189-
190-
stack_entry['func_name'] = boc.frame_description # TODO: integrate 'frame_type' too?
191-
192-
STDERR.print 'frame_id: '
193-
STDERR.puts canonical_fid
194-
stack_entry['frame_id'] = canonical_fid
195-
stack_entry['unique_hash'] = stack_entry['func_name'] + '_f' + stack_entry['frame_id'].to_s
196-
197-
# unsupported features
198-
stack_entry['is_parent'] = false
199-
stack_entry['is_zombie'] = false
200-
stack_entry['parent_frame_id_list'] = []
201-
202-
lvs = iseq_local_variables(iseq)
203-
lvs_val = lvs.inject({}){|r, lv|
204-
begin
205-
v = b.local_variable_get(lv).inspect # TODO: make into true objects later
206-
r[lv] = v
207-
rescue NameError
208-
# ignore
209-
end
210-
r
211-
}
212-
213-
stack_entry['ordered_varnames'] = lvs.map { |e| e.to_s }
214-
stack_entry['encoded_locals'] = lvs_val
219+
stack << stack_entry # only append on success
215220

216221
STDERR.print '>>> ', loc, ' ', lvs, lvs_val
217222
STDERR.puts
@@ -293,7 +298,6 @@ def self.iseq_local_variables iseq
293298
# ignore since we've already handled a :raise event by now
294299
ensure
295300
$stdout = STDOUT
296-
#STDERR.puts JSON.pretty_generate(cur_trace) # pretty-print hack
297301

298302
# postprocessing into a trace
299303
trace_json = JSON.pretty_generate(res)

0 commit comments

Comments
 (0)