hashicorp / go-multierror

A Go (golang) package for representing a list of errors as a single error.
Mozilla Public License 2.0
2.3k stars 123 forks source link

Format nested multi-line errors neatly #30

Closed mentalisttraceur closed 1 year ago

mentalisttraceur commented 4 years ago

This makes the default formatter function robust against errors which have nested \n characters.

The overwhelmingly common case where an error is just one line is unaffected, so I presume this is backwards compatible in all cases where the current behavior is correct and desired.

I think this belongs in the default formatter rather than users having to plug it in because without this, any code that gives you an error in string form might have already "smudged" error information into ambiguous or hard-to-read form if that code used multierror and didn't proactively defend against the possibility of multi-line errors.

mentalisttraceur commented 4 years ago

Also, once this is in place, people like @bits01 and me who have use cases for non-flattened nested multierrors will have a much nicer time implementing that.

Namely, the need to the user to hackishly call multierror.Prefix (see #5 ) goes away.