@@ -224,18 +224,20 @@ def hook_line(probe, &block)
224
224
#
225
225
# If the requested file is not in code tracker's registry,
226
226
# or the code tracker does not exist at all,
227
- # do not attempt to instrumnet now.
227
+ # do not attempt to instrument now.
228
228
# The caller should add the line to the list of pending lines
229
229
# to instrument and install the hook when the file in
230
230
# question is loaded (and hopefully, by then code tracking
231
231
# is active, otherwise the line will never be instrumented.)
232
+ raise_if_probe_in_loaded_features ( probe )
232
233
raise Error ::DITargetNotDefined , "File not in code tracker registry: #{ probe . file } "
233
234
end
234
235
end
235
236
elsif !permit_untargeted_trace_points
236
237
# Same as previous comment, if untargeted trace points are not
237
238
# explicitly defined, and we do not have code tracking, do not
238
239
# instrument the method.
240
+ raise_if_probe_in_loaded_features ( probe )
239
241
raise Error ::DITargetNotDefined , "File not in code tracker registry: #{ probe . file } "
240
242
end
241
243
@@ -352,6 +354,24 @@ def unhook(probe)
352
354
353
355
attr_reader :lock
354
356
357
+ def raise_if_probe_in_loaded_features ( probe )
358
+ # If the probe file is in the list of loaded files
359
+ # (as per $LOADED_FEATURES, using either exact or suffix match),
360
+ # raise an error indicating that
361
+ # code tracker is missing the loaded file because the file
362
+ # won't be loaded again (DI only works in production environments
363
+ # that do not normally reload code).
364
+ if $LOADED_FEATURES. include? ( probe . file )
365
+ raise Error ::DITargetNotInRegistry , "File loaded but is not in code tracker registry: #{ probe . file } "
366
+ end
367
+ # Ths is an expensive check
368
+ $LOADED_FEATURES. each do |path |
369
+ if Utils . path_matches_suffix? ( path , probe . file )
370
+ raise Error ::DITargetNotInRegistry , "File matching probe path (#{ probe . file } ) was loaded and is not in code tracker registry: #{ path } "
371
+ end
372
+ end
373
+ end
374
+
355
375
# TODO test that this resolves qualified names e.g. A::B
356
376
def symbolize_class_name ( cls_name )
357
377
Object . const_get ( cls_name )
0 commit comments