Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make exceptions useful from the command line #79

Merged
merged 1 commit into from
Jan 10, 2013

Conversation

csexton
Copy link
Contributor

@csexton csexton commented Dec 20, 2012

I frequently use curl when testing my apps, but when better_errors intercepts an exception on those requests I get a large output that is unusable at the command line. I simply added an HTML comment to the end of the HTML that includes the exception and backtrace.

This shouldn't effect viewing the page in the browser at all, but makes life at the command line much easier when tracking down errors.

Example output, trimmed for brevity: https://gist.github.com/4347455

I frequently use curl testing in Rails, but when better_errors intercepts
an exception on those requests I get a large output that is unusable at
the command line. I simply added an HTML comment to the end of the HTML
that includes the exception and backtrace.

This shouldn't effect viewing the page in the browser at all, but makes
life at the command line much easier when tracking down errors.

Example output, trimmed for brevity: https://gist.github.com/4347455
@sebmck
Copy link

sebmck commented Dec 23, 2012

Wouldn't a better solution be to check if the user agent is curl or wget and only display that exception and backtrace?

@csexton
Copy link
Contributor Author

csexton commented Dec 23, 2012

@sebmck perhaps, but it seems like switching on the user agent would add unnecessary complexity.

Whereas, always including it in the footer of the html is benign when using a browser. Very helpful on the command line. And we don't have to maintain a list of command line clients that want text only output.

For example, I just started using the awesome httpie client and we would have to update the user agent check to include it.

@rstacruz
Copy link
Collaborator

this seems simple enough to be harmless for now, and it can always be improved later on (user-agent detection and whatnot). thanks for the contribution!

@rstacruz rstacruz closed this Jan 10, 2013
rstacruz added a commit that referenced this pull request Jan 10, 2013
Make exceptions useful from the command line
@rstacruz rstacruz merged commit 068e37f into BetterErrors:master Jan 10, 2013
@rstacruz
Copy link
Collaborator

I've extended this to check for the HTTP Accept header. Browsers typically specify that they prefer text/html, so we serve HTML pages for them, and non-HTML pages for everyone else. No user-agent sniffing necessary.

Tested that it works for curl, wget, Chrome, and Firefox.

@rstacruz
Copy link
Collaborator

Oh, and might I add it makes Markdown-formatted error messages, like this. Perfect for pasting into Trello or Gists.
https://gist.github.com/f2a924c501aec26131e5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants