Unexpected return (LocalJumpError) only when executing this code within autoloaded classes?

Posted on stackoverflow but no traction yet:

The following is a generified part of the code in a gem I’m working on:

module SomeModule
  class << self
    attr_accessor :procedure

    def log_events(*args)
      args.flatten!
      if args.size == 1
        eval "set_trace_func proc {|event, file, line, id, binding,

classname| begin; SomeModule.procedure.call(event, file, line, id,
binding,
classname) if event == #{args[0].inspect}; rescue SystemExit, Interrupt;
raise; rescue Exception; end}"
elsif args.size > 1
eval “set_trace_func proc {|event, file, line, id, binding,
classname| begin; SomeModule.procedure.call(event, file, line, id,
binding,
classname) if #{args.inspect}.include?(event); rescue SystemExit,
Interrupt; raise; rescue Exception; end}”
else
# …
end
end
end
end

SomeModule.procedure = lambda {|event, file, line, id, binding,

classname| puts “#{event} #{file}.#{line} #{binding} #{classname}
#{id}”}

When I then call:

SomeModule.log_events 'call', 'return'

just before the configure block in my Rails app’s
config/environments/development.rb, it works fine and continues to
work.

But, when I call it in app/controllers/application_controller.rb above
or
below the class definition, Rails dies during autoloading in
activesupport-3.2.8/lib/active_support/dependencies.rb:469 due to an
unexpected return (LocalJumpError).

Here is the log:

return

/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/initializable.rb.30
#Binding:0x007ff7b1403d40 Rails::Initializable::Initializer run
return
/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/initializable.rb.54
#Binding:0x007ff7b14039a8 Rails::Initializable run_initializers
return
/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/application.rb.136
#Binding:0x007ff7b1403728 Rails::Application initialize!
return
/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/railtie/configurable.rb.30
#Binding:0x007ff7b1403480 Rails::Railtie::Configurable::ClassMethods
method_missing
call
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb.275
#Binding:0x007ff7b1402aa8 ActiveSupport::Dependencies::Blamable
blame_file!
return
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb.277
#Binding:0x007ff7b1402440 ActiveSupport::Dependencies::Blamable
blame_file!
return
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb.233
#Binding:0x007ff7b1401a40 ActiveSupport::Dependencies::Loadable
load_dependency
return
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb.251
#Binding:0x007ff7b1409790 ActiveSupport::Dependencies::Loadable
require
return
/path/to/.rvm/gems/[email protected]_app_gemset/gems/rack-1.4.1/lib/rack/builder.rb.51
#Binding:0x007ff7b14093f8 Rack::Builder initialize
return
/path/to/.rvm/gems/[email protected]_app_gemset/gems/rack-1.4.1/lib/rack/builder.rb.40
#Binding:0x007ff7b1408ac0 Rack::Builder parse_file
return
/path/to/.rvm/gems/[email protected]_app_gemset/gems/rack-1.4.1/lib/rack/server.rb.200
#Binding:0x007ff7b1408840 Rack::Server app
return
/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/commands/server.rb.46
#Binding:0x007ff7b1408598 Rails::Server app
return
/path/to/.rvm/gems/[email protected]_app_gemset/gems/rack-1.4.1/lib/rack/server.rb.301
#Binding:0x007ff7b14082f0 Rack::Server wrapped_app
return
/path/to/.rvm/gems/[email protected]_app_gemset/gems/rack-1.4.1/lib/rack/server.rb.252
#Binding:0x007ff7b1408048 Rack::Server start
call
/path/to/.rvm/gems/[email protected]_app_gemset/gems/rack-1.4.1/lib/rack/server.rb.179
#Binding:0x007ff7b1407c88 Rack::Server options
return
/path/to/.rvm/gems/[email protected]_app_gemset/gems/rack-1.4.1/lib/rack/server.rb.181
#Binding:0x007ff7b14078f0 Rack::Server options
Exiting
return
/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/commands/server.rb.74
#Binding:0x007ff7b1406ec8 Rails::Server start

/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:469:in
load': unexpected return (LocalJumpError) from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:469:inblock in load_file’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:639:in
new_constants_in' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:468:inload_file’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:353:in
require_or_load' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:502:inload_missing_constant’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:192:in
block in const_missing' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:190:ineach’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:190:in
const_missing' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin/base_controller/menu.rb:2:inmodule:ActiveAdmin
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin/base_controller/menu.rb:1:in
<top (required)>' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:inrequire’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in
block in require' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:inload_dependency’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in
require' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin/base_controller.rb:2:in<top (required)>’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin/resource_controller/actions.rb:2:in
<module:ActiveAdmin>' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin/resource_controller/actions.rb:1:in<top (required)>’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in
require' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:inblock in require’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in
load_dependency' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:inrequire’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin/resource_controller.rb:2:in
<top (required)>' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin/batch_actions.rb:7:inblock in <top (required)>’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin/event.rb:25:in
call' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin/event.rb:25:inblock in dispatch’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin/event.rb:24:in
each' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin/event.rb:24:indispatch’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin/application.rb:179:in
load!' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin/application.rb:205:inroutes’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin.rb:79:in
routes' from /path/to/git/some_app_gemset/config/routes.rb:2:inblock in
<top (required)>’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:282:in
instance_exec' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:282:ineval_block’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:260:in
draw' from /path/to/git/some_app_gemset/config/routes.rb:1:in<top
(required)>’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in
load' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:inblock in load’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in
load_dependency' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:inload’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:40:in
block in load_paths' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:40:ineach’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:40:in
load_paths' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:16:inreload!’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/application.rb:108:in
reload_routes!' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin/reloader.rb:34:inreload!’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activeadmin-0.5.0/lib/active_admin/reloader.rb:61:in
block in attach!' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:429:in_run__1105766863370890952__prepare__156232144867029268__callbacks’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in
__run_callback' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in_run_prepare_callbacks’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in
run_callbacks' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/actionpack-3.2.8/lib/action_dispatch/middleware/reloader.rb:74:inprepare!’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/actionpack-3.2.8/lib/action_dispatch/middleware/reloader.rb:48:in
prepare!' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/application/finisher.rb:47:inblock in module:Finisher
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/initializable.rb:30:in
instance_exec' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/initializable.rb:30:inrun’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/initializable.rb:55:in
block in run_initializers' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/initializable.rb:54:ineach’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/initializable.rb:54:in
run_initializers' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/application.rb:136:ininitialize!’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in
method_missing' from /path/to/git/some_app_gemset/config/environment.rb:5:in<top
(required)>’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in
require' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:inblock in require’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in
load_dependency' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:inrequire’
from /path/to/git/some_app_gemset/config.ru:4:in block in <main>' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/rack-1.4.1/lib/rack/builder.rb:51:ininstance_eval’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/rack-1.4.1/lib/rack/builder.rb:51:in
initialize' from /path/to/git/some_app_gemset/config.ru:1:innew’
from /path/to/git/some_app_gemset/config.ru:1:in <main>' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/rack-1.4.1/lib/rack/builder.rb:40:ineval’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/rack-1.4.1/lib/rack/builder.rb:40:in
parse_file' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/rack-1.4.1/lib/rack/server.rb:200:inapp’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/commands/server.rb:46:in
app' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/rack-1.4.1/lib/rack/server.rb:301:inwrapped_app’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/rack-1.4.1/lib/rack/server.rb:252:in
start' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/commands/server.rb:70:instart’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/commands.rb:55:in
block in <top (required)>' from /path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/commands.rb:50:intap’
from
/path/to/.rvm/gems/[email protected]_app_gemset/gems/railties-3.2.8/lib/rails/commands.rb:50:in
<top (required)>' from script/rails:6:inrequire’
from script/rails:6:in `’

Any idea what I’m doing wrong, or how to determine when and where this
type
of usage of set_trace_func should work?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs