Rails / How to make the error message wrap lines on the development error page

From WhyNotWiki

Jump to: navigation, search

I don't like how if you have an exception with a really long message (for example, if I raise object.inspect), it will all appear on one line and you'll have to scroll possibly 100s of pages to the right just to see it all. Shouldn't it wrap the message if it's too long to fit on one horizontal-width-of-the-screen??

I think so...

This is the solution I've come up with so far...

Just change the [Development error page (category)] (the one that gets rendered by rescue_action_locally).

/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/templates/rescues/diagnostics.rhtml

# diff diagnostics.rhtml.orig diagnostics.rhtml -u
--- diagnostics.rhtml.orig      2007-09-25 10:00:56.000000000 -0700
+++ diagnostics.rhtml   2007-09-25 10:01:55.000000000 -0700
@@ -4,7 +4,7 @@
     in <%=h request.parameters['controller'].humanize %>Controller<% if request.parameters['action'] %>#<%=h request.parameters['action'] %><% end %>
   <% end %>
 </h1>
-<pre><%=h @exception.clean_message %></pre>
+<pre><%=h word_wrap(@exception.clean_message, 160) %></pre>

 <%= render_file(@rescues_path + "/_trace.rhtml", false) %>

But word_wrap doesn't wrap until it finds whitespace before it actually inserts a wrap. I'd rather have it hard wrap after x characters, whether or not there is whitespace there. One of these days maybe I'll figure out how to do that.

Personal tools