-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrap.go
More file actions
42 lines (36 loc) · 1.14 KB
/
wrap.go
File metadata and controls
42 lines (36 loc) · 1.14 KB
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
35
36
37
38
39
40
41
42
package errors
import (
"errors"
"fmt"
"github.com/upfluence/errors/domain"
"github.com/upfluence/errors/message"
"github.com/upfluence/errors/opaque"
)
// New creates a new error with the given message. The error is wrapped with a
// stack frame, domain derived from the calling package, and made opaque.
func New(msg string) error {
return opaque.Opaque(
domain.WithDomain(
WithFrame(errors.New(msg), 1),
domain.PackageDomainAtDepth(1),
),
)
}
// Newf creates a new error with a formatted message. The error is wrapped with a
// stack frame, domain derived from the calling package, and made opaque.
func Newf(msg string, args ...interface{}) error {
return opaque.Opaque(
domain.WithDomain(
WithFrame(fmt.Errorf(msg, args...), 1),
domain.PackageDomainAtDepth(1),
),
)
}
// Wrap wraps an error with an additional message and stack frame.
func Wrap(err error, msg string) error {
return WithFrame(message.WithMessage(err, msg), 1)
}
// Wrapf wraps an error with a formatted message and stack frame.
func Wrapf(err error, msg string, args ...interface{}) error {
return WithFrame(message.WithMessagef(err, msg, args...), 1)
}