3 ms·
IMO the formatting of the error string returned by errors.Join is atrociously opinionated and not very logging-friendly - it adds a newline between each error m
by throwaway173920 2y ago
IMO the formatting of the error string returned by errors.Join is atrociously opinionated and not very logging-friendly - it adds a newline between each error message. I know I'm not the only one that has this opinion
- Matl 2y agoWouldn't you use slog if you want logging friendly?
- kjksf 2y agoIt's a trivial function: https://cs.opensource.google/go/go/+/refs/tags/go1.23.1:src/errors/join.go;l=19 https://cs.opensource.google/go/go/+/refs/tags/go1.23.1:src/... You could write your own errorsJoin() and change Error() method to suit your needs. But really in this particular scenario you would be better served by something like: func errorsConcat(err1 error, err2 error) error { if (err1) { return err1; } return err2; } And then do: err = errorsConcat(err, f.Close()) In the scenario described in this article, errors.Join() would most often reduce to that (in terms of what Error() string would produce).