forked from cockroachdb/errors
/
errutil_api.go
109 lines (84 loc) · 3.8 KB
/
errutil_api.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2019 The Cockroach Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
package errors
import (
"fmt"
"github.com/cockroachdb/errors/barriers"
"github.com/cockroachdb/errors/errbase"
"github.com/cockroachdb/errors/errutil"
)
// New forwards a definition.
func New(msg string) error { return errutil.NewWithDepth(1, msg) }
// NewWithDepth forwards a definition.
func NewWithDepth(depth int, msg string) error { return errutil.NewWithDepth(depth+1, msg) }
// Newf forwards a definition.
func Newf(format string, args ...interface{}) error { return errutil.NewWithDepthf(1, format, args...) }
// NewWithDepthf forwards a definition.
func NewWithDepthf(depth int, format string, args ...interface{}) error {
return errutil.NewWithDepthf(depth+1, format, args...)
}
// Errorf forwards a definition.
func Errorf(format string, args ...interface{}) error {
return errutil.NewWithDepthf(1, format, args...)
}
// Cause is provided for compatibility with github.com/pkg/errors.
func Cause(err error) error { return errbase.UnwrapOnce(err) }
// Unwrap is provided for compatibility with xerrors.
func Unwrap(err error) error { return errbase.UnwrapOnce(err) }
// Wrapper is provided for compatibility with xerrors.
type Wrapper interface {
Unwrap() error
}
// Formatter is provided for compatibility with xerrors.
type Formatter = errbase.Formatter
// Printer is provided for compatibility with xerrors.
type Printer = errbase.Printer
// FormatError can be used to implement the fmt.Formatter interface.
func FormatError(err error, s fmt.State, verb rune) { errbase.FormatError(err, s, verb) }
// Opaque is provided for compatibility with xerrors.
func Opaque(err error) error { return barriers.Handled(err) }
// WithMessage forwards a definition.
func WithMessage(err error, msg string) error { return errutil.WithMessage(err, msg) }
// WithMessagef forwards a definition.
func WithMessagef(err error, format string, args ...interface{}) error {
return errutil.WithMessagef(err, format, args...)
}
// Wrap forwards a definition.
func Wrap(err error, msg string) error { return errutil.WrapWithDepth(1, err, msg) }
// WrapWithDepth forwards a definition.
func WrapWithDepth(depth int, err error, msg string) error {
return errutil.WrapWithDepth(depth+1, err, msg)
}
// Wrapf forwards a definition.
func Wrapf(err error, format string, args ...interface{}) error {
return errutil.WrapWithDepthf(1, err, format, args...)
}
// WrapWithDepthf forwards a definition.
func WrapWithDepthf(depth int, err error, format string, args ...interface{}) error {
return errutil.WrapWithDepthf(depth+1, err, format, args...)
}
// AssertionFailedf forwards a definition.
func AssertionFailedf(format string, args ...interface{}) error {
return errutil.AssertionFailedWithDepthf(1, format, args...)
}
// AssertionFailedWithDepthf forwards a definition.
func AssertionFailedWithDepthf(depth int, format string, args ...interface{}) error {
return errutil.AssertionFailedWithDepthf(depth+1, format, args...)
}
// NewAssertionErrorWithWrappedErrf forwards a definition.
func NewAssertionErrorWithWrappedErrf(origErr error, format string, args ...interface{}) error {
return errutil.NewAssertionErrorWithWrappedErrDepthf(1, origErr, format, args...)
}
// As forwards a definition
func As(err error, target interface{}) bool { return errutil.As(err, target) }