-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.go
34 lines (28 loc) 路 1.06 KB
/
simple.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package terrors
import (
"fmt"
"github.com/rs/zerolog"
)
// New returns an error that formats as the given text.
//
// The returned error contains a Frame set to the caller's location and
// implements Formatter to show this information when printed with details.
func New(text string) *wrapError {
return WrapWithCaller(nil, text, 1)
}
// Errorf formats according to a format specifier and returns the string
// as a value that satisfies error.
//
// The returned error contains a Frame set to the caller's location and
// implements Formatter to show this information when printed with details.
func Errorf(format string, a ...any) *wrapError {
return WrapWithCaller(nil, fmt.Sprintf(format, a...), 1)
}
func Mismatch[T any](expected, actual T) *wrapError {
return WrapWithCaller(nil, "mismatch", 1).Event(func(e *zerolog.Event) *zerolog.Event {
return e.Interface("expected", expected).Interface("actual", actual)
}).(*wrapError)
}
func (me *wrapError) WithMismatch(expected, actual any) *wrapError {
return me.With("expected", expected).With("actual", actual)
}