Hacker News new | past | comments | ask | show | jobs | submit login
Better Rails errors (github.com)
252 points by instakill on Dec 9, 2012 | hide | past | web | favorite | 48 comments

An inline REPL? I love you more than I have words, particularly if you can somehow snag context for it.

The REPL will execute code in the context of the currently selected stack frame.

Agreed. Thank you 1000x!

I love this!

To get it to work with my mixed Padrino/Sinatra rack app I had to do this in each app:

    if PADRINO_ENV == "development"
      set :raise_errors, true
      set :show_exceptions, false

    use BetterErrors::Middleware if PADRINO_ENV == "development"
in my "config.ru".

I'm not deeply familiar with Padrino or Sinatra and so it took a lot of experimentation (and source reading) to find the right incantation. But it's working great now!

another approach, which doesn't require modification of the rackup file:


What safeguards do you have in place to stop the unweary from sticking this into production?

While normally I'm a massive advocate of "Just not being retarded", I suspect a lot of people are going to drop shells as a result of this gem :(

You're right - I've just released 0.0.6 which (among other things) disables better_errors when running under Rails in production.

Awesome. Responsive authors ftw!

Nice, hopefully it can be enabled for people with certain roles, behind VPN, etc?

I was worried about this too when I saw it!

This was always something of a killer feature for me in Python, and one of the reasons I use Flask a lot. Good to see Rails support for in-browser debugging, it's a super convenient workflow to never have to go back to the terminal, just alt-tab from editor to browser.

Your workflow may be good, I don't mean to judge that.

But is not the rails way to be in the shell, rails console and editor at all times? Instead of trying things out in the browser you have automated testing doing that for you?

Why would you ever want to make a web app without constantly testing it in a browser?

Because constantly refreshing the page just to check a variable assignment that could be checked by an automated test is a ridiculous waste of time.

If you've got a decent test suite, it's much faster to leave the browser out of the loop, especially when you're refactoring stuff under the hood.

Thank you for this!

I just found an unintended use for this:

I use pry with a `binding.pry` statement to debug my code, Now I can just `raise 'Something'` to do this instead. One upside of this is that I can easily navigate through all the frames from the UI and inspect stuff. If I want to know what env vars are available in some middleware, I can just click on it in the UI and start inspecting it.

It would be awesome to have this in Rails 4 by default.

A bit late now, but 4.1 could get a campaign for this.

It is not too late to get things into Rails 4. We haven't released a beta yet.

One of the things Rails 4 already features is better error pages, though no REPL.

REPL requires [binding_of_caller](https://github.com/banister/binding_of_caller) anyway, which i doubt rails would include any time soon ;)

That's fair. :)

I stand corrected.

Seems super-useful. Thanks. I see you require binding_of_caller for advanced features (which exactly are those, btw?). That gem only works on 1.9. Do they work on 1.8.7 ? Does the gem work on 1.8.7 at all ?

binding_of_caller is required for the REPL and local/instance variable inspection. 1.8.x is not supported.

I've started building this exact same thing so many times, but never had nearly the follow-through you did. Fantastic job. This has been sorely lacking for many years, and I'm excited to start using it!

Very useful! Better_errors is now an option when generating an application template with the rails_apps_composer gem [1] or the Rails Composer tool [2].

[1] http://railsapps.github.com/rails_apps_composer/ [2] http://railsapps.github.com/rails-composer/

As a Rails n00b, I can't wait to try this.

pry-rescue (https://github.com/ConradIrwin/pry-rescue) is also worth checking out for starting a repl when there is a crash.

Bugsnag (http://bugsnag.com) is awesome when debugging production errors.

Looks fantastic! Keen to try Ruby/Rails soon, and coming from C#/VS land I often find that certain tools are missing in my process, this looks like a great (and in some ways, better) interface to debugging these kind of errors.

I'm a complete rails newbie. I've added 'better_errors' into my Gemfile, started my server/also with Pow and yet I see the same errors as before?

go to the root project in the shell, stop rails server if it's running and type: bundle install

then start the server again: rails server

If he is running under Pow, there's no reason to be running 'script/server' or 'rails server'. That's what Pow does for you.

As with nearly all Rack application servers I know of, you can simply restart the application by creating/updating 'tmp/restart.txt' from your Rails root. Unix's `touch` command does this nicely. With Pow specifically, you can also create '~/.pow/restart.txt' (or '~/Library/Application Support/Pow/Hosts/restart.txt', since it's the same location) and that will force Pow to reload itself.

I didn't know abut 'restart.txt' that's awesome!

Also, I've tried that and I'm still getting the same old "Action Controller: Exception..." error. Specifically I have a MySQL error, yet no 'better_errors' showing.

I've already executed 'bundle install' too.

If you just want to restart a single pow app - in the directory of the rails app run `touch tmp/restart`.

Looking good, I am goind to try it right now.

PS: Probably rack-errors would be much better name for this gem.

or cracked-rack, to make it a bit more punny

Only one comment: WOW!

You guys would be amazed if you tried frameworks like Symfony (instead of discarding PHP for not being beautiful or whatever). It has always had these features, and in Symfony2 it only got more awesome. You even have a complete analysis for each request, that you can open with one click:



Edit: Being downvoted. Some people just don't like knowing the truth.

This isn't a specific draw to PHP, for example several Python frameworks have some flavor of 'debug toolbar' which does the same. Nice feature if you do use PHP otherwise, though.

The downvotes may be partly because you are using an article about a specific Ruby project as a jumping off point to promote another language, which is slightly obnoxious - make a thread for your new PHP stuff you are interested in, people who are happily using Ruby don't need to be exhorted to use other languages for no specific reason

You're being downvoted because your comment (or any comment in the style of 'but Y does this already!') adds no value to the discussion.

Does it have an inline context aware repl? It saves me the trouble of putting the breakpoint, running the request again, and removing the breakpoint.

> You even have a complete analysis for each request, that you can open with one click:

Do I get the queries generated for the request and time it took for them? And the time it took for the templates to be rendered?

Werkzeug debugger and flask-debug-toolbar are my baseline for debugging toolbars. They don't try to be everything and give me everything I need.

> You guys would be amazed if you tried frameworks like Symfony (instead of discarding PHP for not being beautiful or whatever)

Helpful exception logs and inline repls are one of n things to take into consideration. This alone isn't going to buy any converts.

At the end of day, they are convenience tools. It's not like I can't debug code or profile db requests without them. If I can get an inline context aware repl, superb. If not, good old breakpoints are mighty fine.

The PHP ECOSYSTEM has some awesome stuff, I completely agree. A lot of the companies with a decent amount of tech brand behind them in the HN community still use it a lot.

In saying that, the PHP LANGUAGE has some pretty glaring and terrifying warts, a fact that Rasmus doesn't try to hide.

Guys, just because you do Rails doesn't mean you can't get to know other frameworks too.

I came to Rails from Symfony and there are definitely things I miss. Rails is way better overall, but there are loads of little things that were fantastically useful.

The downvotes are overzealous in this case. A comment like this offers useful additional info/context about other languages that offer comparable capability, since many developers keep more than one type of screwdriver in their toolbox (or at least like to stay abreast of how their screwdriver du jour compares with other tools).

fyi rack-mini-profiler does timeline stuff https://github.com/SamSaffron/MiniProfiler/tree/master/Ruby

No offense, but there is no way in hell I would look at that page for hours on end coding, it looks like it was designed in 3 minutes.

Looks to me like a ton of time was put into the design. Don't think this kind of "it sucks but I am not going to explain why" comment really adds much.

thanks alot.... its very useful... <3

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact