You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 12, 2023. It is now read-only.
When using jard to debug a Rails application which is using CurrentAttributes the attributes set on the Current object are coming back as nil. When doing the same debugging with pry the attributes on the Current object are set correctly.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "rails"
#gem "ruby_jard"
#gem "pry"
end
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = __dir__
config.hosts << "example.org"
secrets.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
get "/" => "test#index"
end
end
class Current < ActiveSupport::CurrentAttributes
attribute :request
end
class TestController < ActionController::Base
include Rails.application.routes.url_helpers
before_action do
Current.request = request
end
def index
render plain: "Home"
end
end
require "minitest/autorun"
require "rack/test"
class BugTest < Minitest::Test
include Rack::Test::Methods
def test_returns_success
get "/"
#jard
#binding.pry
assert last_response.ok?
assert Current.request.uuid.present?
end
private
def app
Rails.application
end
end
If you run it as-is the tests should pass.
If you uncomment the Jard lines (lines 10 and 55) then run it again the jard debugger starts up. If you continue out of it the tests pass. But the bug is that on the Jard debugging REPL the Current attributes are nil.
jard >> Current.request.class
=> NilClass
jard >> Current.request.uuid
NoMethodError: undefined method `uuid' for nil:NilClass
from (pry):2:in `test_returns_success'
If you instead uncomment the pry lines (11 and 56) then the tests pass and the Current attributes are accessible through the debugging REPL.
Wow. I'm surprised by the detail level of your bug report. I appreciate your times, and efforts helping me on this. This bug is indeed a big issue. The root cause of this bug is that jard evaluates user input in a seperate thread different the stopping thread. It was a good idea to solve a performance issue at first, but now it turns to be a flawed solution. It would take me a while to implement a permanent fix for this issue. So, I'll let you know when it's ready in master branch 🙏
@nguyenquangminh0711 I thought it might be something like that - sounds like it's quite low-level and fundamental to the architecture, I hope the fix isn't too painful! Thanks for your reply 🙏
Describe the bug
When using jard to debug a Rails application which is using CurrentAttributes the attributes set on the Current object are coming back as
nil
. When doing the same debugging with pry the attributes on the Current object are set correctly.To Reproduce
Here's a single file Rails application based on the Rails bug report template for controllers.
If you run it as-is the tests should pass.
If you uncomment the Jard lines (lines 10 and 55) then run it again the jard debugger starts up. If you
continue
out of it the tests pass. But the bug is that on the Jard debugging REPL the Current attributes arenil
.If you instead uncomment the pry lines (11 and 56) then the tests pass and the Current attributes are accessible through the debugging REPL.
Expected behavior
Jard's debugging REPL should behave the same as Pry's and have access to
Current.request
.Environment (please complete the following information):
tput colors
in your terminal: 256echo $TERM
in your terminal: xterm-256stty
:speed 38400 baud; line = 0;
-brkint -imaxbel iutf8
Also not on your list but I've tried this on Ruby 2.6.6 and 2.7.2, on Rails 6.0.3.4
Thanks ❤️ Jard looks incredible!
The text was updated successfully, but these errors were encountered: