Sinatra and custom pretty errors in production on ubuntu - error-handling

I'm tearing my hair out. On my mac, custom pretty errors are shown that I want to display to my users. When I deploy to my ubuntu box I get a minimal black and white error message instead.
I've got sinatra error handling, like so
set :raise_errors, false
set :show_exceptions, false
not_found do
erb :'errors/not_found'
end
I assumed it was because I was running nginx and thin (on ubuntu) but if I bypass this stack and run direct I still have the problem on ubuntu.
ruby start.rb #I get a minimal black and white error
OR
rackup -E production config.ru #I get a minimal black and white error
OR
rackup -E development config.ru #I get rack stack trace
I get pretty error on my mac, regardless of how I start and even if I use Rack::ShowExceptions. I'm running ruby 1.9.2 and sinatra 1.3.2.
Any clues as to how I can get pretty errors to users in production?

Okay, after several failed attempts to fix this over several weeks, I realised I was doing something stupid. I was missing [email_errors][to] in my production config.yaml. This was breaking my error_handler. Had I read the rack stack trace when I added 'use Rack::ShowExceptions' to my config.ru, I would have seen the problem, except I didn't read it because the error_handler was throwing the same error I was expecting from my test error. Stupid oversight.

Related

Error message: NameError at /users/sign_in undefined local variable or method `require_no_authentication' for #<SessionsController:0x########>

I'm working on a RoR app with Devise. When I came in to work today and tried to start up my local dev environment, RoR failed when I tried to go to the sign in page:
NameError at /users/sign_in
undefined local variable or method `require_no_authentication' for #<SessionsController:0x########>
It looks like the error is not being raised within the code we wrote, but instead from deep within the Devise gem. I'm guessing that somehow, my dev machine isn't configured right.
Here are some things I've tried to fix the bug:
I ran rake db:migrate and rake db:terraform.
I ran bundle install.
I ran rvm gemset empty and bundle install to reinstall all of my gems.
None of these worked.
In addition, here are a couple more strange things about this error:
None of the other devs at my workplace are having the same error, even though they're on the same codebase.
After trying to figure out the error for a while, I switched to a branch that I haven't updated since before I started getting this bug. Even though it was working before the weekend, that branch now fails with the same error.
Does anybody know anything I could do to try to fix this error? Does it sound like some part of my local configuration is incorrectly set up?
In my project, I had added a file in app/controllers called devise_controller.rb. It looked like this:
class DeviseController < ApplicationController
# Asks Devise how much time is left until the current user is
# automatically logged out, without resetting the logout timer.
def time_until_logout
raise "let's inspect here"
end
end
When I deleted this file, the bug went away.
I filed a bug report about how adding a DeviseController caused RoR/Devise to blow up on Devise's repository: https://github.com/plataformatec/devise/issues/2520

How do I resolve Unexpected character '' error when precompiling assets in Rails?

I am trying to deploy my app for the first time and running into problems with the asset pipeline. When I run bundle exec rake assets:precompile I get the following error;
cool_app#ip-10-248-17-168:/rails_apps/cool_app/current$ bundle exec rake assets:precompile
/home/cool_app/.rvm/rubies/ruby-1.9.3-p327/bin/ruby /rails_apps/cool_app/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
Unexpected character '' (line: 13934, col: 1, pos: 403510)
Error
at new JS_Parse_Error (<eval>:1720:22)
at js_error (<eval>:1728:15)
at parse_error (<eval>:1824:17)
at next_token (<eval>:2070:17)
at handle_slash (<eval>:2024:32)
at Object.next_token [as input] (<eval>:2067:39)
at next (<eval>:2175:37)
at Object.semicolon [as 1] (<eval>:2221:38)
at prog1 (<eval>:2770:28)
at simple_statement (<eval>:2362:35)
(in /rails_apps/cool_app/releases/20121128034720/app/assets/javascripts/application.js)
I presume that this means I have an illegal character (that's not rendering) somewhere in my maze of javascript (should have deployed earlier!) but telling me it's at column 1 on line 13934 doesn't seem to be particularly useful. How do I go about hunting this down? The error message is spectacularly unhelpful (and I notice a lot of other questions on this theme here too).
Edit -
I'm not sure of the significance, but if I run RAILS_ENV=development rake assets:precompile on my development machine, the task seems to execute without complaint. My Server is Ubuntu 12.04 and my dev machine in OSX 10.8. I don't know enough about Javascript runtimes to solve this myself right now (but I'm hunting).
Hokay,
My head hurts from the hours of bashing it against my keyboard but I solved my problem.
First, some reading around suggested that uglifier was the cause of my error. I set config.assets.compress = false in config/production.rb and sure enough I was able to precompile my assets.
I wasn't happy with this though as my Javascript file was 625kB and I really wanted it compressed, so I looked in the generated application.js file and found what line 13934, column 1 referred to. Turns out it was line 8, column 1 of the file jquery.caret.1.02.js, a small jQuery plugin I am using. This first line looks like so;
(function($,len,createRange,duplicate){
with a space in front of the line. I deleted that space (I suspect it is some incorrect non-printing unicode character but haven't bothered looking into it), set config.assets.compress = true, and tried again and no more error message! (and my Javascript is down to 159kB)
I hope that this helps someone one day.
another reason might be html-style comments in your js files.
this will produce
Unexpected character '<'
just to bring it out there, hope it saves someone some time and trouble
I've been bashing my head on this problem for a while as well. For me, the issue was in using the gem uglifier. When I removed uglifier and ran bundle exec rake assets:precompile again, I was successful.
It seems to a javascript compression issue, generally speaking. See what gems you are using to compress your JS

Heroku + Rails: weird error (Cedar Stack)

So I have deployed my app to heroku for testing for a couple of weeks and since yesterday I keep getting the following kind of errors in the heroku logs:
Started GET "/user/shipping_address" for xx.xxx.xxx at 2012-02-09 15:46:37 +0000
NameError (undefined local variable or method `sign_up_path' for #<UsersController:0x000000036210a8>):
app/controllers/application_controller.rb:57:in `require_user'
Another one:
Started POST "/purchase/search" for xx.xxx.xxx at 2012-02-09 15:31:30 +0000
NameError (undefined local variable or method `sign_up_path' for #<PurchasesController:0x000000051a3d08>):
app/controllers/application_controller.rb:57:in `require_user'
I also keep getting (really) weird javascript errors in firebug, like "object_id" missing, where object_id should never be used at that point in code.
It works without any flaws in the local environment on development/production and also all the time before on my heroku app.
Any hints greatly appreciated. This error is really killing me.
Best, Phil
(Cedar-Stack, Rails 3.0, authlogic)
Ok I updated authlogic to the newest version 3.1.0 (think it was on 3.0.3) and everything works for now.

Nokogiri on Mac: "Symbol not found: _xmlAddChild" How do I fix this?

I have been running Cucumber for my Rails app for quite some time without problems. Looks like something changed (but I don't know what), because now Nokogiri does not want to work. Apparently it's having trouble finding the symbol "_xmlAddChild". Not sure I even know what that means. Can you point me in the direction of reading material that can educate me, or suggest a solution?
Here's my error output:
/Users/me/.rvm/rubies/ruby-1.9.3-p0/bin/ruby -S bundle exec cucumber --profile default
Using the default profile...
dlopen(/Users/me/Sites/myapp/nokogiri/ruby/1.9.1/gems/nokogiri-1.5.0/lib/nokogiri/nokogiri.bundle, 9): Symbol not found: _xmlAddChild
Referenced from: /Users/me/Sites/myapp/nokogiri/ruby/1.9.1/gems/nokogiri-1.5.0/lib/nokogiri/nokogiri.bundle
Expected in: flat namespace
in /Users/me/Sites/myapp/nokogiri/ruby/1.9.1/gems/nokogiri-1.5.0/lib/nokogiri/nokogiri.bundle - /Users/me/Sites/myapp/nokogiri/ruby/1.9.1/gems/nokogiri-1.5.0/lib/nokogiri/nokogiri.bundle (LoadError)
Here's what I've found online:
http://rubyforge.org/tracker/index.php?func=detail&aid=27256&group_id=494&atid=1971
I tried updating the nokogiri gem alone, and with all other gems. No luck so far.
Really stupid solution here. The problem arose when another developer on the project put this line into the features/support/env.rb file used to run Cucumber.
require 'capybara'
It doesn't seem to serve a purpose, and when I removed it, the whole issue went away. I really have no idea what the error involving "_xmlAddChild" was.

Debugging heroku 500 server error?

So this is what I get from looking at my production.logs from heroku:
Completed 200 OK in 63ms (Views: 6.0ms | ActiveRecord: 50.3ms)
Processing by EventsController#show as HTML
Parameters: {"id"=>"2"}
Rendered events/show.html.erb within layouts/application (3.7ms)
Completed 500 Internal Server Error in 15ms
Everything works locally and I have even pushed the database to heroku using db:push. Is there any more robust logging for heroku than the lines above that aren't helpful?
I'm sure its because you haven't ran rake db:migrate
If that does not work make sure that all the gems you need are in your Gem file, i.e. you are not making any local require statements to gems not in the Gemfile.
What I have found helpful is tailing the log.
And then you need to run this in console:
heroku logs --tail
Now click on the same page you were getting problems at before and check out the logs.
EDIT: on rails 4 you'll need to add the rails_12factor gem to get the detailed logs.
This isn't related to ruby but it might be good information for other googlers.
My issue not being able to see the actual error was that I was using a third party PHP tool that did this: # mysql_connect( ... ) which simply hides the error that that function didn't exist .. really evil code