binding_of_caller icon indicating copy to clipboard operation
binding_of_caller copied to clipboard

Error using with better_errors and basic rails apps

Open ni-ka opened this issue 10 years ago • 10 comments

Hey,

as @badosu fixed my problems with jruby (thanks for that!), I tried again starting new with a fresh rails app composer app (Gemfile here: https://gist.github.com/ni-ka/6811586)

Unfortunately I am getting the following error. Bettererrors works fine if I remove binding_of_caller. I started the app with JRUBY_OPTS=-X-C rails s

Started GET "/" for 127.0.0.1 at 2013-10-03 17:13:55 +0200

ArgumentError - index out of bounds for java array (-1 for length 160): org/jruby/java/proxies/ArrayJavaProxy.java:79:in []' () Users/nils/.rvm/gems/jruby-1.7.4@bettertest/bundler/gems/binding_of_caller-132db08acaf0/lib/binding_of_caller/jruby_interpreted.rb:20:inbinding_of_caller' () Users/nils/.rvm/gems/jruby-1.7.4@bettertest/bundler/gems/binding_of_caller-132db08acaf0/lib/binding_of_caller/jruby_interpreted.rb:33:in of_caller' () Users/nils/.rvm/gems/jruby-1.7.4@bettertest/bundler/gems/binding_of_caller-132db08acaf0/lib/binding_of_caller/jruby_interpreted.rb:37:incallers' org/jruby/RubyRange.java:459:in each' org/jruby/RubyEnumerable.java:713:inmap' () Users/nils/.rvm/gems/jruby-1.7.4@bettertest/bundler/gems/binding_of_caller-132db08acaf0/lib/binding_of_caller/jruby_interpreted.rb:37:in callers' better_errors (1.0.1) lib/better_errors/core_ext/exception.rb:9:inset_backtrace' actionpack (4.0.0) lib/abstract_controller/helpers.rb:152:in initialize' actionpack (4.0.0) lib/abstract_controller/helpers.rb:137:inmodules_for_helpers' org/jruby/RubyArray.java:2449:in map!' actionpack (4.0.0) lib/abstract_controller/helpers.rb:130:inmodules_for_helpers' actionpack (4.0.0) lib/action_controller/metal/helpers.rb:89:in modules_for_helpers' actionpack (4.0.0) lib/abstract_controller/helpers.rb:94:inhelper' actionpack (4.0.0) lib/abstract_controller/helpers.rb:171:in default_helper_module!' actionpack (4.0.0) lib/abstract_controller/helpers.rb:22:ininherited' org/jruby/RubyModule.java:2245:in module_eval' actionpack (4.0.0) lib/abstract_controller/helpers.rb:22:ininherited' actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:226:in inherited' actionpack (4.0.0) lib/abstract_controller/railties/routes_helpers.rb:7:ininherited' actionpack (4.0.0) lib/action_controller/railties/helpers.rb:5:in inherited' app/controllers/visitors_controller.rb:1:in(root)' org/jruby/RubyKernel.java:1073:in load' activesupport (4.0.0) lib/active_support/dependencies.rb:1:in(root)' activesupport (4.0.0) lib/active_support/dependencies.rb:423:in load_file' activesupport (4.0.0) lib/active_support/dependencies.rb:615:innew_constants_in' activesupport (4.0.0) lib/active_support/dependencies.rb:422:in load_file' activesupport (4.0.0) lib/active_support/dependencies.rb:323:inrequire_or_load' activesupport (4.0.0) lib/active_support/dependencies.rb:462:in load_missing_constant' org/jruby/RubyModule.java:2546:inconst_get' activesupport (4.0.0) lib/active_support/dependencies.rb:183:in const_missing' org/jruby/RubyArray.java:1617:ineach' org/jruby/RubyEnumerable.java:815:in inject' activesupport (4.0.0) lib/active_support/inflector/methods.rb:226:inconstantize' activesupport (4.0.0) lib/active_support/inflector/methods.rb:224:in constantize' activesupport (4.0.0) lib/active_support/dependencies.rb:534:inget' activesupport (4.0.0) lib/active_support/dependencies.rb:565:in constantize' actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:76:incontroller_reference' actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:66:in controller' actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:44:incall' org/jruby/RubyArray.java:1617:in each' actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:incall' actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in call' actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:incall' rack (1.5.2) lib/rack/etag.rb:23:in call' rack (1.5.2) lib/rack/conditionalget.rb:25:incall' rack (1.5.2) lib/rack/head.rb:11:in call' actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:incall' actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in call' rack (1.5.2) lib/rack/session/abstract/id.rb:225:incontext' rack (1.5.2) lib/rack/session/abstract/id.rb:220:in call' actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:incall' actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in call' org/jruby/RubyBasicObject.java:1703:insend' org/jruby/RubyKernel.java:2209:in send' activesupport (4.0.0) lib/active_support/callbacks.rb:376:in_run__2080399955__call__callbacks' activesupport (4.0.0) lib/active_support/callbacks.rb:80:in run_callbacks' actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:incall' actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in call' actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:incall' better_errors (1.0.1) lib/better_errors/middleware.rb:84:in protected_app_call' better_errors (1.0.1) lib/better_errors/middleware.rb:79:inbetter_errors_call' better_errors (1.0.1) lib/better_errors/middleware.rb:56:in call' actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:incall' actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in call' railties (4.0.0) lib/rails/rack/logger.rb:38:incall_app' railties (4.0.0) lib/rails/rack/logger.rb:21:in call' activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:intagged' activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in tagged' activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:intagged' railties (4.0.0) lib/rails/rack/logger.rb:21:in call' quiet_assets (1.0.2) lib/quiet_assets.rb:18:incall_with_quiet_assets' actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in call' rack (1.5.2) lib/rack/methodoverride.rb:21:incall' rack (1.5.2) lib/rack/runtime.rb:17:in call' activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:incall' rack (1.5.2) lib/rack/lock.rb:17:in call' actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:incall' railties (4.0.0) lib/rails/engine.rb:511:in call' railties (4.0.0) lib/rails/application.rb:97:incall' rack (1.5.2) lib/rack/lock.rb:17:in call' rack (1.5.2) lib/rack/content_length.rb:14:incall' rack (1.5.2) lib/rack/handler/webrick.rb:60:in service' /Users/nils/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/webrick/httpserver.rb:138:inservice' /Users/nils/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/webrick/httpserver.rb:94:in `run'

ni-ka avatar Oct 03 '13 15:10 ni-ka

This is probably due to https://github.com/banister/binding_of_caller/commit/479b0003458484bf972dc6b60f7e57b3332103ba

badosu avatar Oct 03 '13 15:10 badosu

Yes, that is it. Using the old code works.

ni-ka avatar Oct 03 '13 15:10 ni-ka

Ok, I am going to revert it.

But if I had only the failing case in which it happens, I could add a test.

Do you have any indication?

badosu avatar Oct 03 '13 16:10 badosu

Cool, check out this repo https://github.com/ni-ka/bettertest. However it is a full rails app so not sure how you want to use it for your tests. I used jruby 1.7.4 on osx mountain lion to produce the error, in case it matters.

ni-ka avatar Oct 04 '13 22:10 ni-ka

Thanks! Gonna check it out.

badosu avatar Oct 04 '13 22:10 badosu

Thanks @ni-ka for your support on this.

https://github.com/banister/binding_of_caller/commit/a6a362206e8cbce9ea30129d279adc915d839c60 should solve the biggest problem (the exception inside of own binding_of_caller).

However, better errors stil doesn't show the repl neither the scope variables.

badosu avatar Oct 06 '13 01:10 badosu

Any idea why that is by the way?

ni-ka avatar Oct 06 '13 08:10 ni-ka

@badosu I've played around with Jruby a bit. Check out this fork https://github.com/vincentwoo/better_errors especially https://github.com/vincentwoo/better_errors/commit/2f4b16c904eb7a4e5084c3354618280266967982 there is a pull request pending. With that changes the binding_of_caller method is at least called properly. I then had an exception about a missing method frame_description for binding. I created it so that it returns a static string but got stuck with another exception:

Java::JavaLang::NullPointerException (): org.jruby.parser.StaticScope.determineModule(StaticScope.java:344) org.jruby.parser.StaticScope.determineModule(StaticScope.java:344) org.jruby.evaluator.ASTInterpreter.evalWithBinding(ASTInterpreter.java:170) org.jruby.RubyKernel.evalCommon(RubyKernel.java:1130) org.jruby.RubyKernel.eval19(RubyKernel.java:1093) org.jruby.RubyKernel$INVOKER$s$0$3$eval19.call(RubyKernel$INVOKER$s$0$3$eval19.gen) org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:217) org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:213) org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:202) org.jruby.ast.CallTwoArgNode.interpret(CallTwoArgNode.java:59) org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)

I'll leave the experiments to you ;-)

ni-ka avatar Oct 15 '13 21:10 ni-ka

@ni-ka could you check 3f3244c4f57dfda9917058c8de8843c68c27ad4a (i.e. HEAD) with jruby 1.7.6?

Using it with regular better_errors seems to work.

However, as you pointed out, we don't define the frame_{type,description} methods. I don't have any idea on how to implement them. See the discussion @ https://github.com/banister/binding_of_caller/commit/edeb9a9863764add0b1fcb900e90ffd5675fb46a

badosu avatar Nov 05 '13 16:11 badosu

In jruby 1.7.6:

[1] pry(main)> b = binding.of_caller(1)
=> #<Java::OrgJrubyRuntime::Binding:0x1045dfe>
[2] pry(main)> b.backtrace
RubyToJavaInvoker.java:178:in `castJavaProxy': java.lang.ClassCastException: org.jruby.RubyBinding cannot be cast to org.jruby.java.proxies.JavaProxy

badosu avatar Nov 05 '13 16:11 badosu

Closing this issue, if someone is still experiencing issues with jruby, please let me know.

prpetten avatar Mar 13 '24 03:03 prpetten