~rogpeppe/goose/state-of-the-world

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Utility functions for reporting errors.

package errors

import (
	"errors"
	"fmt"
)

// AddErrorContext prefixes any error stored in err with text formatted
// according to the format specifier. If err does not contain an error,
// AddErrorContext does nothing.
func AddErrorContext(err *error, format string, args ...interface{}) {
	if *err != nil {
		*err = errors.New(fmt.Sprintf(format, args...) + ": " + (*err).Error())
	}
}