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
@ -m gives "Error: Cannot find method code." and $ is giving syntax error #2254
Comments
That's really odd 🤔 I've tried the same using the gem versions. Can you run the following cmds and let me know the result:
This should at least point us if it's something in pry or method_source. Sorry for the long list! |
|
Thanks for the additional details. I've tried this on Rails 5.1.7 app too and still trying to reproduce and understand what's happening here. It does look like a problem with method_source, as calling MethodSource tries to 'eval' the code until it finds a complete expression. Can you run: file, line = self.method(:attribute_was).source_location ; File.readlines(file)[(line-1)..(line+5)] So we can see what the code that should be being eval'd looks like? For me, it returns:
Another idea would be to monkey-patch https://github.com/banister/method_source/blob/master/lib/method_source/code_helpers.rb#L66 to see what method_source is trying to eval when it breaks with a SyntaxError. |
Yup yup. Same thing. #>>> file, line = self.method(:attribute_was).source_location ; File.readlines(file)[(line-1)..(line+5)]
# => [" def attribute_was(*_attr)\n",
" emit_warning_if_needed(\"attribute_was\", \"attribute_before_last_save\")\n",
" super\n",
" end\n",
"\n",
" def attribute_change(*_attr)\n",
" emit_warning_if_needed(\"attribute_change\", \"saved_change_to_attribute\")\n"] Doping
so it is indeed a syntax error... just not sure WHY it is a syntax error at that level. Why I seem to be seeing, and no clue why this is different this time around (new machine and all, but Gemfile.lock should put me right, right?)
winds up calling: that last one is the "eval clean or raise" ... but it shouldn't be "or raise"... it should be "eval clean or false" so it appends the next line of source and tries again. Yes, I think this is it... module MethodSource
module CodeHelpers
def complete_expression?(str)
old_verbose = $VERBOSE
$VERBOSE = nil
catch(:valid) do
eval("BEGIN{throw :valid}\n#{str}")
end
# Assert that a line which ends with a , or \ is incomplete.
str !~ /[,\\]\s*\z/
rescue IncompleteExpression, SyntaxError # Added SyntaxError Here!!!
false
ensure
$VERBOSE = old_verbose
end
end
end why is this coming up now?!? I have NO clue. Who is supposed to be raising OK. I think this is dumb, but probably the culprit:
Why am I having a hard time now?!?! I have NO idea. TBH it seems dumb. I had a hell of a time getting a build of ruby 2.6 working on arm64 w/ ruby-install ... it appears postmodern refuses to maintain any patches ... had I installed via rbenv or something else maybe this would work fine?!? I dunno... I do know that my company is most likely migrating to 2.7 sometime next week. If this really is a one off... (how? why?)... then ignore this ticket. I have a workaround and I'm moving to a version where this Just Works™ already. |
Basically, pry is able to show surrounding context, but any use of method_source (I'm assuming) seems to be totally broken and I can't figure out why. I've already cleared out my pryrc to no avail.
Some context: this was working fine and then work gave me a new machine. I switched over from intel to arm... but this stuff works on my personal arm machine, so IDGI.
I can't introspect on Pry itself because of the above errors, so I'm at a bit of a loss here. Tell me what to poke at and I'll poke at it.
The text was updated successfully, but these errors were encountered: