We would like to support emitting errors in different ways, for example as JSON or HTML. The former for easier integration with IDEs, the latter for better user understanding. The main impediment to these more structured forms is that our error messages are not particularly structured. In particular, when we issue notes, help messages, or suggestions with an error message, these are treated as independent messages with no relation. I would like to have the notes associated with the errors.
I see two ways to do this: either we support error transactions, so a multi-part error message looks like:
handler.start_transaction(); handler.span_err(...); handler.span_note(...); handler.span_note(...); handler.end_transaction();
or we support structured exceptions:
let mut err = span_err(...); err.note(...); err.note(...); handler.report(err);
Some of the constraints are that we should be able to handle notes which are not in the same function as the error and we should strive to make orphan notes a static error, rather than a compile-time one (if possible).
Does anyone have any better designs? Or an opinion on these two? I think I prefer the second, although the first would be less work to implement (since existing code would still compile (if we admit single errors without transactions), which also means it is potentially buggier).