Skip to content

Use "pre-wrap" format and monospace font for exception messages#1925

Merged
ioquatix merged 2 commits into
rack:mainfrom
mame:showexceptions-as-pre
Jul 9, 2022
Merged

Use "pre-wrap" format and monospace font for exception messages#1925
ioquatix merged 2 commits into
rack:mainfrom
mame:showexceptions-as-pre

Conversation

@mame

@mame mame commented Jul 8, 2022

Copy link
Copy Markdown
Contributor

This PR makes Rack::ShowExceptions friendly to Ruby 3.1's error_highlight. An exception message should be rendered by a monospace font and in "pre" format, i.e., whitespaces are preserved and newlines are respected.

Before:

image

After:

image

Ruby 3.1's error_highlight feature prints a code snippet with a
underline. To make it readable, an exception message should be rendered
by a monospace font and in "pre" format, i.e., whitespaces are preserved
and newlines are respected.
@jeremyevans

Copy link
Copy Markdown
Contributor

I like this change, but what happens when the exception message is very long? We don't want this to require horizontal scrolling. One approach would be to use monospace font, but turn newlines into <br>.

... to allow automatic line wrapping for very long lines.
@mame

mame commented Jul 8, 2022

Copy link
Copy Markdown
Contributor Author

@jeremyevans Thank you for your review!

what happens when the exception message is very long? We don't want this to require horizontal scrolling.

It's a fair point. I changed the css to white-sprace: pre-wrap, which allows automatic line wrapping. How about this?

@jeremyevans jeremyevans left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-wrap looks like a good approach.

@mame mame changed the title Use "pre" format and monospace font for exception messages Use "pre-wrap" format and monospace font for exception messages Jul 8, 2022
@ioquatix
ioquatix merged commit 28d25c2 into rack:main Jul 9, 2022
@ioquatix

ioquatix commented Jul 9, 2022

Copy link
Copy Markdown
Member

Thanks! This is better than what we currently have, so I'll merge it. But I'd personally like to see better formatting when dealing with HTML as an output. Seems like we we could do a lot better and I imagine lots of people are consuming error messages this way.

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