Skip to content

Commit b686bc6

Browse files
committed
cleaned up cod
1 parent 79f685e commit b686bc6

1 file changed

Lines changed: 15 additions & 46 deletions

File tree

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

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@
7373
class MaxStepsException < RuntimeError
7474
end
7575

76+
def encode_object(obj)
77+
return obj.inspect # TODO: make into a rich object and fill up the heap
78+
end
79+
80+
81+
# end all of my own definitions here so that I can set the following vars ...
7682

7783
# collect the sets of these variables RIGHT BEFORE the user's code runs
7884
# so that we can do a set difference later to see what the user defined
@@ -88,15 +94,11 @@ class MaxStepsException < RuntimeError
8894

8995
raise MaxStepsException if n_steps > MAX_STEPS
9096

91-
#STDERR.puts '---'
92-
#STDERR.puts [tp.event, tp.lineno, tp.path, tp.defined_class, tp.method_id].inspect
9397
# TODO: look into tp.defined_class and tp.method_id attrs
9498

9599
retval = nil
96100
if tp.event == :return || tp.event == :b_return
97-
#STDERR.print 'RETURN!!! '
98-
#STDERR.puts tp.return_value.inspect
99-
retval = tp.return_value.inspect # TODO: make into true objects later
101+
retval = encode_object(tp.return_value)
100102
end
101103

102104
evt_type = case tp.event
@@ -114,8 +116,6 @@ class MaxStepsException < RuntimeError
114116

115117
# make a copy to take a snapshot at this point in time
116118
entry['stdout'] = stdout_buffer.string.dup
117-
#STDERR.print 'stdout: '
118-
#STDERR.puts entry['stdout']
119119

120120
stack = []
121121
heap = {} # TODO: xxx
@@ -127,27 +127,19 @@ class MaxStepsException < RuntimeError
127127
entry['globals'] = globals
128128

129129
true_globals = (global_variables - base_globals_set) # set difference
130-
#STDERR.print 'Globals: '
131-
#STDERR.puts true_globals.inspect
132130
entry['ordered_globals'] = true_globals.map { |e| e.to_s }
133131

134132
true_globals.each.with_index do |varname, i|
135133
val = eval(varname.to_s) # TODO: is there a better way? this seems hacky!
136-
#STDERR.print varname, ' -> ', val.inspect
137-
#STDERR.puts
138-
globals[varname.to_s] = val.inspect # TODO: make into true objects later
134+
globals[varname.to_s] = encode_object(val)
139135
end
140136

141137
# toplevel constants (stuff them in globals)
142138
toplevel_constants = (Module.constants - base_constants_set) # set difference
143-
#STDERR.print 'Constants: '
144-
#STDERR.puts toplevel_constants.inspect
145139
entry['ordered_globals'] += toplevel_constants.map { |e| e.to_s }
146140
toplevel_constants.each do |varname|
147141
val = eval(varname.to_s) # TODO: is there a better way? this seems hacky!
148-
#STDERR.print varname, ' -> ', val.inspect
149-
#STDERR.puts
150-
globals[varname.to_s] = val.inspect # TODO: make into true objects later
142+
globals[varname.to_s] = encode_object(val)
151143
end
152144

153145
# toplevel methods, class vars, and instance vars
@@ -158,40 +150,28 @@ class MaxStepsException < RuntimeError
158150
toplevel_class_vars = Object.class_variables - base_class_vars_set
159151
toplevel_inst_vars = self.instance_variables - base_inst_vars_set
160152

161-
#STDERR.puts 'toplevel_methods: %s' % toplevel_methods.inspect
162-
#STDERR.puts 'toplevel_class_vars: %s' % toplevel_class_vars.inspect
163-
#STDERR.puts 'toplevel_inst_vars: %s' % toplevel_inst_vars.inspect
164-
165153
entry['ordered_globals'] += toplevel_methods.map { |e| e.to_s }
166154
entry['ordered_globals'] += toplevel_class_vars.map { |e| e.to_s }
167155
entry['ordered_globals'] += toplevel_inst_vars.map { |e| e.to_s }
168156

169157

170158
toplevel_methods.each do |varname|
171159
val = Object.method(varname)
172-
#STDERR.print varname, ' -> ', val.inspect
173-
#STDERR.puts
174-
globals[varname.to_s] = val.inspect # TODO: make into true objects later
160+
globals[varname.to_s] = encode_object(val)
175161
end
176162

177163
toplevel_class_vars.each do |varname|
178164
val = Object.class_variable_get(varname)
179-
#STDERR.print varname, ' -> ', val.inspect
180-
#STDERR.puts
181-
globals[varname.to_s] = val.inspect # TODO: make into true objects later
165+
globals[varname.to_s] = encode_object(val)
182166
end
183167

184168
toplevel_inst_vars.each do |varname|
185169
val = self.instance_variable_get(varname)
186-
#STDERR.print varname, ' -> ', val.inspect
187-
#STDERR.puts
188-
globals[varname.to_s] = val.inspect # TODO: make into true objects later
170+
globals[varname.to_s] = encode_object(val)
189171
end
190172

191173
if tp.event == :raise
192-
#STDERR.print 'RAISE!!! '
193-
#STDERR.puts tp.raised_exception.inspect
194-
entry['exception_msg'] = tp.raised_exception.inspect # TODO: make into true objects later
174+
entry['exception_msg'] = encode_object(tp.raised_exception)
195175
end
196176

197177
# adapted from https://github.com/ko1/pretty_backtrace/blob/master/lib/pretty_backtrace.rb
@@ -238,8 +218,6 @@ def self.iseq_local_variables iseq
238218
stack_entry['func_name'] = '%s:%d' % [loc.label, loc.lineno]
239219

240220

241-
#STDERR.print 'frame_id: '
242-
#STDERR.puts canonical_fid
243221
stack_entry['frame_id'] = canonical_fid
244222
stack_entry['unique_hash'] = stack_entry['func_name'] + '_f' + stack_entry['frame_id'].to_s
245223

@@ -251,8 +229,8 @@ def self.iseq_local_variables iseq
251229
lvs = iseq_local_variables(iseq)
252230
lvs_val = lvs.inject({}){|r, lv|
253231
begin
254-
v = b.local_variable_get(lv).inspect # TODO: make into true objects later
255-
r[lv] = v
232+
v = b.local_variable_get(lv)
233+
r[lv] = encode_object(v)
256234
rescue NameError
257235
# ignore
258236
end
@@ -272,11 +250,6 @@ def self.iseq_local_variables iseq
272250
end
273251
end
274252

275-
#STDERR.puts 'is_main: %s' % is_main
276-
#STDERR.print '>>> ', loc, ' ', lvs, lvs_val
277-
#STDERR.puts
278-
#STDERR.puts
279-
280253
# no separate frame for main since its local variables were folded
281254
# into globals
282255
if !is_main
@@ -286,8 +259,6 @@ def self.iseq_local_variables iseq
286259
end
287260
end
288261

289-
#STDERR.puts
290-
291262
# massage the topmost stack entry
292263
if stack.length > 0
293264
stack[0]['is_highlighted'] = true
@@ -367,8 +338,6 @@ def self.iseq_local_variables iseq
367338
end
368339
rescue
369340
$stdout = STDOUT
370-
STDERR.puts "other exception -- EEEEEEEE!!!"
371-
STDERR.puts $!
372341
# ignore since we've already handled a :raise event in the trace by now
373342
ensure
374343
$stdout = STDOUT

0 commit comments

Comments
 (0)