errors
Sentinel Error
var invalidValueErr = errors.New("Invalid value for diagnosticv2 message")
Later use by "wrapping" it with additional details:
return fmt.Errorf("%w: %s topic", invalidValueErr, mtgext.CallNetwork)
Use in tests like:
func SomeTest() {
err := updateCallNetwork("garbagestring")
errors.Is(err, invalidValueErr) // returns true, don't need to rely on specific error strings
}
Summary:
Not necessary for every error
Useful if error is part of an API
Useful to help testing
More info: https://go.dev/blog/go1.13-errors
Last updated