问题
I'm currently getting an error that looks like this:
NoMethodError: undefined method `debug' for nil:NilClass
/mnt/hgfs/Dropbox/Company/Project/lib/project/misc.rb:23:in `debug'
/mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:49:in `block in compare_addresses'
/mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:43:in `each'
/mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:43:in `compare_addresses'
/mnt/hgfs/Dropbox/Company/Project/lib/project/validation/google_geocoding_validation_engine.rb:32:in `valid?'
/mnt/hgfs/Dropbox/Company/Project/specs/project/validation/google_geocoding_validation_engine_spec.rb:56:in `block (2 levels) in <module:Validation>'
/home/tomas/ruby2/lib/ruby/2.0.0/minitest/unit.rb:1301:in `run'
I figured I'd try using byebug to figure out why the object is nil
since it's never supposed to be nil
. I placed byebug
just above the erroneous line:
def debug(&block)
if @logger.nil?
byebug
end
@logger.debug(@logger_name, &block)
end
And ran the tests. I was dropped to the byebug debugging interface and could confirm that the object was indeed nil
. The problem is that I can't climb up the stack:
(byebug) up
*** Adjusting would put us beyond the oldest (initial) frame.
(byebug) down
*** Adjusting would put us beyond the newest (innermost) frame.
(byebug) backtrace
--> #0 AddressKit::Misc::Logging.debug(block#Proc) at /mnt/hgfs/Dropbox/Kvantel/Address Kit/lib/addresskit/misc.rb:25
Warning: saved frames may be incomplete; compare with caller(0)
Why can't I go up the stack? Is this an issue with byebug or perhaps an incompatibility with MiniTest?
回答1:
Answer for byebug >= 1.5.0
Printing and moving around the callstack in situations like this one should just work and the OP wouldn't have this issue.
Answer for byebug < 1.5.0 (also applicable to debugger or ruby-debug)
Byebug won't start tracking down callstack information until Byebug.start
is called, which is internally called by the byebug
command. So by the time you get the debugging prompt, only one callstack frame has been saved, that's why you get that message:
Warning: saved frames may be incomplete; compare with caller(0)
and that's why you can't move up
or down
: there's only one frame.
To properly navigate the stack, you need to start Byebug higher up, by dropping Byebug.start
wherever you want to start tracking down callstack info. For example, before line 56 in google_geocoding_validation_engine_spec.rb
. If you want full stack information, you can run byebug from the outset, by running the byebug executable:
byebug rake
or however you are running your specs.
If you still have issues, please let me know!
Hope this helps.
来源:https://stackoverflow.com/questions/17044127/how-do-i-scale-the-stack-when-debugging-with-byebug