I'm using ruby 2.1.0 and Rails 4.1.0
If I put a debugger statement anywhere in my rake code, I get this:
home/vagrant/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/monitor.rb:213
mon_exit
[208, 217] in /home/vagrant/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/monitor.rb
208 def mon_synchronize
209 mon_enter
210 begin
211 yield
212 ensure
=> 213 mon_exit
214 end
215 end
216 alias synchronize mon_synchronize
217
(rdb:1)
I cannot access any of the local variables in my code.
Monitor appears to be a threading library... so how do I get the debugger statement to run properly?
The issue was putting "debugger" at the end of a method, which would make it the return value.
The fix... don't put debugger at the end of a method.
Related
I recently installed Rollbar on my to-be Production instance and I see that Rollbar has starting reporting this issue about not finding a WordPress login.
ActionController::RoutingError: No route matches [GET] "/blog/wp-login.php"
I searched through all my code and dont find any references wp-login.php and the stack trace is not helping either. Would you know where this might be coming from?
"/home/myproject/shared/bundle/ruby/2.1.0/gems/actionpack-4.0.13/lib/action_dispatch/middleware/debug_exceptions.rb" line 21 in call
"/home/myproject/shared/bundle/ruby/2.1.0/gems/rollbar-2.7.1/lib/rollbar/middleware/rails/show_exceptions.rb" line 22 in call_with_rollbar
"/home/myproject/shared/bundle/ruby/2.1.0/gems/actionpack-4.0.13/lib/action_dispatch/middleware/show_exceptions.rb" line 30 in call
"/home/myproject/shared/bundle/ruby/2.1.0/gems/railties-4.0.13/lib/rails/rack/logger.rb" line 38 in call_app
"/home/myproject/shared/bundle/ruby/2.1.0/gems/railties-4.0.13/lib/rails/rack/logger.rb" line 20 in block in call
"/home/myproject/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.13/lib/active_support/tagged_logging.rb" line 68 in block in tagged
"/home/myproject/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.13/lib/active_support/tagged_logging.rb" line 26 in tagged
"/home/myproject/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.13/lib/active_support/tagged_logging.rb" line 68 in tagged
"/home/myproject/shared/bundle/ruby/2.1.0/gems/railties-4.0.13/lib/rails/rack/logger.rb" line 20 in call
"/home/myproject/shared/bundle/ruby/2.1.0/gems/actionpack-4.0.13/lib/action_dispatch/middleware/request_id.rb" line 21 in call
"/home/myproject/shared/bundle/ruby/2.1.0/gems/rack-1.5.5/lib/rack/methodoverride.rb" line 21 in call
"/home/myproject/shared/bundle/ruby/2.1.0/gems/rack-1.5.5/lib/rack/runtime.rb" line 17 in call
"/home/myproject/shared/bundle/ruby/2.1.0/gems/actionpack-4.0.13/lib/action_dispatch/middleware/static.rb" line 84 in call
"/home/myproject/shared/bundle/ruby/2.1.0/gems/rack-1.5.5/lib/rack/send.rb" line 112 in call
"/home/myproject/shared/bundle/ruby/2.1.0/gems/railties-4.0.13/lib/rails/engine.rb" line 511 in call
"/home/myproject/shared/bundle/ruby/2.1.0/gems/railties-4.0.13/lib/rails/application.rb" line 97 in call
"/home/myproject/shared/bundle/ruby/2.1.0/gems/railties-4.0.13/lib/rails/railtie/configurable.rb" line 30 in method_missing
"/home/myproject/shared/bundle/ruby/2.1.0/gems/unicorn-5.0.1/lib/unicorn/http_server.rb" line 562 in process_client
"/home/myproject/shared/bundle/ruby/2.1.0/gems/unicorn-5.0.1/lib/unicorn/http_server.rb" line 658 in worker_loop
"/home/myproject/shared/bundle/ruby/2.1.0/gems/unicorn-5.0.1/lib/unicorn/http_server.rb" line 508 in spawn_missing_workers
"/home/myproject/shared/bundle/ruby/2.1.0/gems/unicorn-5.0.1/lib/unicorn/http_server.rb" line 132 in start
"/home/myproject/shared/bundle/ruby/2.1.0/gems/unicorn-5.0.1/bin/unicorn" line 126 in <top (required)>
"/home/myproject/shared/bundle/ruby/2.1.0/bin/unicorn" line 23 in load
"/home/myproject/shared/bundle/ruby/2.1.0/bin/unicorn" line 23 in <main>
This is just the random background noise of the internet - scripts wander around looking for known security holes (in this case, one in WordPress) that their human might want to exploit. If someone ever puts your link into an MS Office document, you'll also see weird OPTIONS requests.
It's common to configure error reporting to ignore RoutingErrors, though of course there are pros and cons to that. It lets you ignore this noise, which can trigger false alarms, but if you ever actually render a bad URL, it can go unnoticed.
I just experienced my app having errors on every page load or almost every page load. A restart cleared out all the problems. Here is what I think happened.
The first error, was "IOError: could not reopen: null"
"org/jruby/RubyIO.java" line 501 in reopen
"/app/vendor/bundle/jruby/1.9/gems/activesupport-4.0.4/lib/active_support/core_ext/kernel/reporting.rb" line 52 in silence_stream
"/app/vendor/bundle/jruby/1.9/gems/activesupport-4.0.4/lib/active_support/core_ext/kernel/reporting.rb" line 109 in quietly
"/app/vendor/bundle/jruby/1.9/gems/activesupport-4.0.4/lib/active_support/core_ext/kernel/reporting.rb" line 50 in silence_stream
"/app/vendor/bundle/jruby/1.9/gems/activesupport-4.0.4/lib/active_support/core_ext/kernel/reporting.rb" line 108 in quietly
"/app/vendor/bundle/jruby/1.9/gems/activerecord-session_store-0.1.0/lib/action_dispatch/session/active_record_store.rb" line 64 in get_session
"/app/vendor/bundle/jruby/1.9/gems/rack-1.5.2/lib/rack/session/abstract/id.rb" line 266 in load_session
"/app/vendor/bundle/jruby/1.9/gems/actionpack-4.0.4/lib/action_dispatch/middleware/session/abstract_store.rb" line 43 in load_session
"/app/vendor/bundle/jruby/1.9/gems/actionpack-4.0.4/lib/action_dispatch/middleware/session/abstract_store.rb" line 51 in stale_session_check!
"/app/vendor/bundle/jruby/1.9/gems/actionpack-4.0.4/lib/action_dispatch/middleware/session/abstract_store.rb" line 43 in load_session
"/app/vendor/bundle/jruby/1.9/gems/actionpack-4.0.4/lib/action_dispatch/request/session.rb" line 168 in load!
"/app/vendor/bundle/jruby/1.9/gems/actionpack-4.0.4/lib/action_dispatch/request/session.rb" line 160 in load_for_read!
"/app/vendor/bundle/jruby/1.9/gems/actionpack-4.0.4/lib/action_dispatch/request/session.rb" line 86 in []
"/app/vendor/bundle/jruby/1.9/gems/warden-1.2.3/lib/warden/session_serializer.rb" line 30 in fetch
"/app/vendor/bundle/jruby/1.9/gems/warden-1.2.3/lib/warden/proxy.rb" line 212 in user
...
There was only one of those. Then, on every page request, i get "Errno::EBADF: Bad file descriptor"
"org/jruby/RubyIO.java" line 2097 in close
"/app/vendor/bundle/jruby/1.9/gems/activesupport-4.0.4/lib/active_support/core_ext/kernel/reporting.rb" line 53 in silence_stream
"/app/vendor/bundle/jruby/1.9/gems/activesupport-4.0.4/lib/active_support/core_ext/kernel/reporting.rb" line 109 in quietly
"/app/vendor/bundle/jruby/1.9/gems/activesupport-4.0.4/lib/active_support/core_ext/kernel/reporting.rb" line 50 in silence_stream
"/app/vendor/bundle/jruby/1.9/gems/activesupport-4.0.4/lib/active_support/core_ext/kernel/reporting.rb" line 108 in quietly
"/app/vendor/bundle/jruby/1.9/gems/activerecord-session_store-0.1.0/lib/action_dispatch/session/active_record_store.rb" line 64 in get_session
"/app/vendor/bundle/jruby/1.9/gems/rack-1.5.2/lib/rack/session/abstract/id.rb" line 266 in load_session
"/app/vendor/bundle/jruby/1.9/gems/actionpack-4.0.4/lib/action_dispatch/middleware/session/abstract_store.rb" line 43 in load_session
...
What cause the initial problem?
weird stuff such as these are likely caused by Rails not being "absolutely" thread-safe (even on MRI but it's more obvious on JRuby since it's "GIL-free") ... Rails.logger.silence and related have not been 100% thread-safe https://gist.github.com/kares/9374772 I've dealt with similar issues (on JRuby on Rails) since 2.3 and there sure were attempts to fix this but somehow the same silencing logic keeps getting back.
the whole silence_stream(STDOUT) {} code (that your trace reveals), I would guess, might end up in a similar "unpredictable" state. I would try patching kernel/reporting.rb so that the stream silencers do nothing (I've updated the gist as well).
When stepping through the Ruby Debugger in Rails, how do I only have it stop only at code that I wrote, skipping over all the native Rails code?
(ie skipping all the code that looks like this)
/Users/jon/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/core_ext/module/remove_method.rb:4
remove_method(method)
(rdb:1) s
[76, 85] in /Users/jon/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/core_ext/class/attribute.rb
76 def self.#{name}?() !!#{name} end
77
78 def self.#{name}=(val)
79 singleton_class.class_eval do
80 remove_possible_method(:#{name})
=> 81 define_method(:#{name}) { val }
82 end
83
84 if singleton_class?
85 class_eval do
/Users/jon/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/core_ext/class/attribute.rb:81
define_method(:#{name}) { val }
(rdb:1) s
[79, 88] in /Users/jon/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.2.1/lib/active_support/core_ext/class/attribute.rb
79 singleton_class.class_eval do
80 remove_possible_method(:#{name})
81 define_method(:#{name}) { val }
82 end
83
=> 84 if singleton_class?
85 class_eval do
86 remove_possible_method(:#{name})
87 def #{name}
88 defined?(##{name}) ? ##{name} : singleton_class.#{name}
Thanks!
I think what your looking for is something like this if I understand your question right.
You'll want to step over rather than step into, that way if your using a method for rails you don't go into the rails code. I hope this helps and good luck.
If you occasionally stepped in some Rails code, just press c in a console. This will move you to the next breakpoint you have set (or return to the same one if you're inside a loop) or will simply end page request if there's no breakpoints left.
There are 3 major debugging commands
c - Continue
s - Step into
n - next/ Step over
What you're looking for is "n", it allows you to go through a list of methods without going into the code or ruby gem that contains the rest of the code.
I get the following error:
Vpim::InvalidEncodingError (email#email.net):
2011-06-07T01:37:06+00:00 app[web.1]: .bundle/gems/ruby/1.8/gems/vpim-0.695/lib/vpim/field.rb:110:in `decode0'
It has worked fine for other vcards. And the data looks right -- it should be an email:
Here is a sample vcard that blows up when there's an email...what I"ve done to fix it is manually remove the second email, but that's a pain:
BEGIN:VCARD
VERSION:2.1
N:Roberts;Paul;;;
FN:Paul Roberts
ORG:Sonoma Technology Inc
TITLE:EVP Business Dev/Chief Scientific Officer
TEL;WORK;VOICE:707-665-9900
TEL;WORK;FAX:707-665-9800
ADR;WORK;ENCODING=QUOTED-PRINTABLE:;;1455 N McDowell Blvd Suite D;Petaluma;CA;94954;USA
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:1455 N McDowell Blvd Suite D=0D=0APetaluma, CA 94954=0D=0AUSA
URL:http://www.sonomatech.com
URL:http://www.sonomatech.com
EMAIL;PREF;INTERNET:paul#sonomatech.com
paul#sonomatech.com
NOTE;ENCODING=QUOTED-PRINTABLE:=0D=0A Data provided by Lead411, http://www.lead411.com/=0D=0A =0D=0A
END:VCARD
Here's my controller using paperclip and vpim:
68 unless #contact.vcard.path.blank?
69
70 paperclip_vcard = File.new(#contact.vcard.path)
71
72 # try to scrub the vcard
73 scrub_vcf(paperclip_vcard)
74
75 #vcard = Vpim::Vcard.decode(paperclip_vcard).first
76 #contact.title = #vcard.title
77 #contact.email = #vcard.email
78 #contact.first_name = #vcard.name.given
79 #contact.last_name = #vcard.name.family
80 #contact.phone = #vcard.telephones[0]
81 #contact.fax = #vcard.telephones[1]
82
83 #contact.address.street1 = #vcard.address.street
84 #contact.address.city = #vcard.address.locality
85 #contact.address.state = #vcard.address.region
86 #contact.address.zip = #vcard.address.postalcode
87 #contact.company_name = #vcard.org.fetch(0)
88
89 end
You need to look at how your Vcards are being created; the second email on line 14 isn't a valid property definition, which is what's causing the parser to screw up (and which is why it parses successfully if you manually delete it).
You can read about the property definition in Section 2 in the Vcard 2.1 specification (the RTF version–which is far more readable–is available here).
From the information you provided, this doesn't look like a problem with Vpim on the decoding side, but rather how your Vcards are created. If you're creating the Vcards yourself, I'd take a look at your encoding logic. If you're receiving them from outside sources, then you might want to write some custom scrubbing logic to get rid of improper property definitions, so you don't have to manually remove them yourself.
You should be able to do this quite easily with a quick regex check on each line:
def scrub_vcf(vcard)
line_arr = File.readlines(vcard)
line_arr.delete_if { |line| line.match(/^.+\:.+$/).nil? }
File.open(vcard, "w") do |f|
line_arr.each{|line| f.puts(line)}
end
end
# use the scrubbed vcf with vpim
Of course, it would probably be quicker to keep this in an array rather than writing it back out to a file, FYI.
Hope that helps.
UPDATE: If you don't want to keep the file, you can return a string, which Vpim can decode instead of a file:
def scrub_vcf(vcard)
line_arr = File.readlines(vcard)
line_arr.delete_if { |line| line.match(/^.+\:.+$/).nil? }
return line_arr.join
end
# use the scrubbed vcf with vpim #=> Vpim::Vcard.decode(scrub_vcf(vcard))
Note that I ran into problems with using a String with Vpim::Vcard.decode when running ruby 1.9.x, due to the fact that the String class no longer has an each method. Ruby 1.8.7 works fine, though. Vpim looks like it hasn't been upgraded since 2008/2009, so it's probably not been upgraded for use with ruby 1.9.x.
UPDATE AGAIN: Here's a version of Vpim updated for use with ruby 1.9.x (fixes precisely the issue I ran into earlier): https://github.com/sam-github/vpim
I am working on rails project and I am trying to get exceptions to be logged to the rails log files. I know I can call logger.error $! to get the first line of the exception logged to the file. But, I want to get the entire trace stack logged as well. How do I log the entire trace back of an exception using the default rails logger?
logger.error $!.backtrace
Also, don't forget you can
rescue ErrorType => error_name
to give your error a variable name other than the default $!.
The way rails does it is
137 logger.fatal(
138 "\n\n#{exception.class} (#{exception.message}):\n " +
139 clean_backtrace(exception).join("\n ") +
140 "\n\n"
141 )
248 def clean_backtrace(exception)
249 if backtrace = exception.backtrace
250 if defined?(RAILS_ROOT)
251 backtrace.map { |line| line.sub RAILS_ROOT, '' }
252 else
253 backtrace
254 end
255 end
256 end
In later versions of Rails, simply uncomment the following line in RAIL_ROOT/config/initializers/backtrace_silencers.rb (or add this file itself if it's not there):
# Rails.backtrace_cleaner.remove_silencers!
This way you get the full backtrace written to the log on an exception. This works for me in v2.3.4.
logger.error caller.join("\n") should do the trick.
In Rails, ActionController::Rescue deals with it. In my application controller actions, i'm using method log_error from this module to pretty-format backtrace in logs:
def foo_action
# break something in here
rescue
log_error($!)
# call firemen
end
Here's how I would do it:
http://gist.github.com/127708
Here's the ri documentation for Exception#backtrace:
http://gist.github.com/127710
Note that you could also use Kernel#caller, which gives you the full trace (minus the curent frame) as well.
http://gist.github.com/127709
Also - Note that if you are trying to catch all exceptions, you should rescue from Exception, not RuntimeError.
You can also use ruby's default variables, like this:
logger.error "Your error message. Exception message:#{$!} Stacktrace:#{$#}"