This repository has been archived by the owner on Jan 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors.go
65 lines (51 loc) · 1.66 KB
/
errors.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
package croconf
import (
"errors"
"fmt"
"strconv"
)
var ErrorMissing = errors.New("field is missing in config source") // TODO: remove?
type BindFieldMissingError struct {
SourceName string
Field string // search field
}
func NewBindFieldMissingError(srcName string, field string) *BindFieldMissingError {
return &BindFieldMissingError{SourceName: srcName, Field: field}
}
func (e *BindFieldMissingError) Error() string {
return fmt.Sprintf("field %s is missing in config source %s", e.Field, e.SourceName)
}
type BindValueError struct {
Func string // the failing function (like BindIntValueTo)
Input string // the input
Err error // the reason the conversion failed
}
func NewBindValueError(f string, input string, err error) *BindValueError {
var numErr *strconv.NumError
if errors.As(err, &numErr) {
err = numErr.Err
}
return &BindValueError{
Func: f, Input: input, Err: err,
}
}
// Error implements error interface
func (e *BindValueError) Error() string {
return e.Func + ": " + "parsing " + strconv.Quote(e.Input) + ": " + e.Err.Error()
}
func (e *BindValueError) Unwrap() error { return e.Err }
func (e *BindValueError) withFuncName(funcName string) *BindValueError {
return NewBindValueError(funcName, e.Input, e.Err)
}
type JSONSourceInitError struct {
Data []byte // the failing data input
Err error
}
func NewJSONSourceInitError(data []byte, err error) *JSONSourceInitError {
return &JSONSourceInitError{Data: data, Err: err}
}
// Error implements error interface
func (e *JSONSourceInitError) Error() string {
return "source json initialization failed: data=" + string(e.Data)
}
func (e *JSONSourceInitError) Unwrap() error { return e.Err }