Project

General

Profile

Actions

Feature #19019

open

Nicely formatted exception messages in HTML

Added by ioquatix (Samuel Williams) about 2 years ago. Updated about 2 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:110039]

Description

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.

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0