ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "ioquatix (Samuel Williams)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:110042] [Ruby master Bug#19019] Nicely formatted exception messages in HTML
Date: Fri, 23 Sep 2022 08:39:44 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-99292.20220923083944.3344@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-19019.20220923075232.3344@ruby-lang.org

Issue #19019 has been updated by ioquatix (Samuel Williams).


> I believe that what kind of HTML fragment is needed is not up to error_highlight or the authors of exception classes, but up to each framework.

That's a fair approach. But I'd prefer a simple interface for formatting HTML exceptions without having to sniff the version of Ruby or the features available. I'd like Ruby to be able to improve formatting and support new kinds of exceptions without the code that prints exceptions having to change. I'd be quite happy with `exception.full_message(highlight: :html)` for Rack for example. As your PR to Rails shows, the current implementation is non-trivial and requires a lot of work in the framework code.

----------------------------------------
Bug #19019: Nicely formatted exception messages in HTML
https://bugs.ruby-lang.org/issues/19019#change-99292

* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
We have made a lot of improvements to exception formatting. See https://bugs.ruby-lang.org/issues/18296 for details.

I'd like us to consider adding support for HTML formatting of messages, e.g.

```
exception.full_message(highlight: :html)
```

or something to that effect.

Another option is to convert terminal style errors to html by converting control characters. However, I'm less optimistic about parsing sequences like `^^^^^` to apply a style to the above line.

Maybe it's sufficient when `highlight: true` is specified to avoid `^^^^^` characters.

When I've personally implemented this in the past, I've used a formatting object, e.g.

```ruby
exception.full_message(highlight: HTMLFormatter.new)
```

The formatter has a rich interface for printing, and uses a set of abstractions to map to the underlying output.

e.g.

```
formatter.puts(:exception, "NoMethodError", :reset, ": ", :message, "undefined method 'bar' for ", :object, "#<Foo...>")
formatter.puts(:code, "x = foo", :error, ".bar, :reset)
```

This can be easily mapped to HTML, XTerm, plain text, json, etc.



-- 
https://bugs.ruby-lang.org/

      parent reply	other threads:[~2022-09-23  8:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-23  7:52 [ruby-core:110039] [Ruby master Bug#19019] Nicely formatted exception messages in HTML ioquatix (Samuel Williams)
2022-09-23  8:15 ` [ruby-core:110041] " mame (Yusuke Endoh)
2022-09-23  8:39 ` ioquatix (Samuel Williams) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-99292.20220923083944.3344@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).