Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rails console on reload: undefined method `end_line=' for nil (NoMethodError) #685

Open
thisIsLoading opened this issue Aug 22, 2024 · 3 comments

Comments

@thisIsLoading
Copy link

Hi,

everytime i reload! the rails console i get this error:

irb(main):008> reload!
Reloading...
(irb):8:in `<main>': undefined method `end_line=' for nil (NoMethodError)

      node.end_line   = @end_line
          ^^^^^^^^^^^^^
irb(main):009> 

it was annoying but didnt bother me enough to dig a little deeper. but today was the day. so i searched my whole computer for that line and ended up in the psych gem folder right here:

node.end_column = @end_column

    def set_end_location(node)
      node.end_line   = @end_line
      node.end_column = @end_column
    end`

it is obviously not the actual cause of the issue but has anyone an idea how i could figure out where the issue is?

thanks in advance!

@tinbka
Copy link

tinbka commented Oct 28, 2024

I case anyone comes to this page after me, this just means you have a syntax error in your code. I got this when I got an incorrectly misplaced closing braces in a long expression in IRB. That's weird that the issue opener got this from reload! though, I thought reload! usually reports syntax errors just fine.

@pedros007
Copy link

pedros007 commented Nov 1, 2024

I've had the same problem for years. I finally took time to research and found this very issue. To find the "syntax error" I ran this a rails console session:

begin
  reload!
rescue => e
  puts e.full_message(highlight: true, order: :top)
end

and buried in the stack trace was the line of my problematic application code:

FactoryBot.define do
  factory :coords do
    x {123}
    y {456}   #  <=== this is the problematic line!
  end
end

It turns out y is defined for psych!

psych/lib/psych/y.rb

Lines 4 to 7 in ac15c01

# An alias for Psych.dump_stream meant to be used with IRB.
def y *objects
puts Psych.dump_stream(*objects)
end

I can make my factory work by changing my factory from y { 456 } to add_attribute(:y) { 456 }... but perhaps psych's y is an overly generic method name that only runs in irb?

@thisIsLoading
Copy link
Author

@pedros007 thank you so much for posting this. i just confirmed this to be the root cause on my end as well. i have a grid system which stores the length and height in x and y and i totally will not change this on my end because that would mean ripping apart the guts and a nightmare to put it all back together

FactoryBot.define do
  factory :widget do
    dashboard { nil }
    x { 1 }
    y { 1 }
    width { 1 }
    height { 1 }
    category { 1 }
    config { "" }
  end
end

i agree that psych should not be using just y here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants