binding_of_caller
binding_of_caller copied to clipboard
Error using with better_errors and basic rails apps
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:in
binding_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:in
callers'
org/jruby/RubyRange.java:459:in each' org/jruby/RubyEnumerable.java:713:in
map'
() 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:in
set_backtrace'
actionpack (4.0.0) lib/abstract_controller/helpers.rb:152:in initialize' actionpack (4.0.0) lib/abstract_controller/helpers.rb:137:in
modules_for_helpers'
org/jruby/RubyArray.java:2449:in map!' actionpack (4.0.0) lib/abstract_controller/helpers.rb:130:in
modules_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:in
helper'
actionpack (4.0.0) lib/abstract_controller/helpers.rb:171:in default_helper_module!' actionpack (4.0.0) lib/abstract_controller/helpers.rb:22:in
inherited'
org/jruby/RubyModule.java:2245:in module_eval' actionpack (4.0.0) lib/abstract_controller/helpers.rb:22:in
inherited'
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:in
inherited'
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:in
new_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:in
require_or_load'
activesupport (4.0.0) lib/active_support/dependencies.rb:462:in load_missing_constant' org/jruby/RubyModule.java:2546:in
const_get'
activesupport (4.0.0) lib/active_support/dependencies.rb:183:in const_missing' org/jruby/RubyArray.java:1617:in
each'
org/jruby/RubyEnumerable.java:815:in inject' activesupport (4.0.0) lib/active_support/inflector/methods.rb:226:in
constantize'
activesupport (4.0.0) lib/active_support/inflector/methods.rb:224:in constantize' activesupport (4.0.0) lib/active_support/dependencies.rb:534:in
get'
activesupport (4.0.0) lib/active_support/dependencies.rb:565:in constantize' actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:76:in
controller_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:in
call'
org/jruby/RubyArray.java:1617:in each' actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in
call'
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:in
call'
rack (1.5.2) lib/rack/etag.rb:23:in call' rack (1.5.2) lib/rack/conditionalget.rb:25:in
call'
rack (1.5.2) lib/rack/head.rb:11:in call' actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in
call'
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in call' rack (1.5.2) lib/rack/session/abstract/id.rb:225:in
context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in call' actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in
call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in call' org/jruby/RubyBasicObject.java:1703:in
send'
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:in
call'
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:in
call'
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:in
better_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:in
call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in call' railties (4.0.0) lib/rails/rack/logger.rb:38:in
call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in call' activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in
tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in tagged' activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in
tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in call' quiet_assets (1.0.2) lib/quiet_assets.rb:18:in
call_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:in
call'
rack (1.5.2) lib/rack/runtime.rb:17:in call' activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in
call'
rack (1.5.2) lib/rack/lock.rb:17:in call' actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in
call'
railties (4.0.0) lib/rails/engine.rb:511:in call' railties (4.0.0) lib/rails/application.rb:97:in
call'
rack (1.5.2) lib/rack/lock.rb:17:in call' rack (1.5.2) lib/rack/content_length.rb:14:in
call'
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:in
service'
/Users/nils/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/webrick/httpserver.rb:94:in `run'
This is probably due to https://github.com/banister/binding_of_caller/commit/479b0003458484bf972dc6b60f7e57b3332103ba
Yes, that is it. Using the old code works.
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?
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.
Thanks! Gonna check it out.
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.
Any idea why that is by the way?
@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 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
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
Closing this issue, if someone is still experiencing issues with jruby, please let me know.