Previously, error formatting logic was based on a single linear chain
of causality. Error causes would be printed vertically down the page,
and their interpretation was natural.
This commit adds multi-cause formatting support with two goals in
mind:
Preserve output exactly as before for single-cause error chains
Format multi-errors in a way that preserves the existing vertical
layout style.
For non-verbose error display (.Error(), %s, %v) there are no
changes implemented here. We rely on the error's own display logic and
typically a multi-cause error will have a message within that has been
constructed from all of its causes during instantiation.
For verbose error display (%+v) which relies on object
introspection, whenever we encounter a multi-cause error in the chain,
we mark that subtree as being displayed with markers for the "depth"
of various causes. All child errors of the parent, will be at depth
"1", their child errors will be at depth "2", etc. During display, we
indent the error by its "depth" and add a └─ symbol to illustrate
the parent/child relationship.
Example:
Printing the error produced by this construction using the format directive %+v
The top-level single cause chain maintains the left-aligned Wrap
lines which contain each cause one at a time.
As soon as we hit the multi-cause errors within the joinError
struct ((3)), we add new indentation to show that The child errors
of (3) are (4) and (8)
Subsequent causes of errors after joinError, are also indented to
disambiguate the causal chain
The Error types section at the bottom remains the same and the
numbering of the types can be matched to the errors above using the
integers next to the Wrap lines.
No special effort has been made to number the errors in a way that
describes the causal chain or tree. This keeps it easy to match up the
error to its type descriptor.
Note for reviewers: only take a look at final commit
@knz updated last PR and added a detailed example of changes. Tried to keep this pass simple and note in test comments the specific tweaks I want to fix later.
Previously, error formatting logic was based on a single linear chain of causality. Error causes would be printed vertically down the page, and their interpretation was natural.
This commit adds multi-cause formatting support with two goals in mind:
For non-verbose error display (
.Error()
,%s
,%v
) there are no changes implemented here. We rely on the error's own display logic and typically a multi-cause error will have a message within that has been constructed from all of its causes during instantiation.For verbose error display (
%+v
) which relies on object introspection, whenever we encounter a multi-cause error in the chain, we mark that subtree as being displayed with markers for the "depth" of various causes. All child errors of the parent, will be at depth "1", their child errors will be at depth "2", etc. During display, we indent the error by its "depth" and add a└─
symbol to illustrate the parent/child relationship.Example:
Printing the error produced by this construction using the format directive
%+v
Produces the following output:
Note the following properties of the output:
Wrap
lines which contain each cause one at a time.joinError
struct ((3)
), we add new indentation to show that The child errors of(3)
are(4)
and(8)
joinError
, are also indented to disambiguate the causal chainError types
section at the bottom remains the same and the numbering of the types can be matched to the errors above using the integers next to theWrap
lines.Note for reviewers: only take a look at final commit
This change is![Reviewable](https://reviewable.io/review_button.svg)