Skip to content

Separate content vs presentation for error types (need render method) #7865

@Ericson2314

Description

@Ericson2314

Problem

Current our error infrastructure (Error and subclasses) store a format string. This is fine for one off ad-hoc errors, but a problem for structured errors. Those structured errors have various fields (so when caught data can be manipulated without having to parse a string), and those fields duplicate the information stored in the format string.

It also makes awkward attempts to display in the information in other ways, such as with JSON logging (where we might want to display the fields in an object, rather than just give the machine-unfriendly format string).

Solution

We really ought have a separate virtual method for rendering errors. Ad-hoc errors can still store the format string like today, and their render implementation would just display it. However structured errors would forego storing a format string entirely, and just do any string formatting that is needed on the fly as part of the render implementation.

This is much clearer, and makes structured errors (which we should encourage!) easier to use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    error-messagesConfusing messages and better diagnostics

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions