-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
43 lines (35 loc) · 927 Bytes
/
error.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
// Copyright (c) 2023, Roel Schut. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rawconv
import (
"reflect"
"strconv"
"github.com/go-pogo/errors"
)
type UnsupportedTypeError struct {
Type reflect.Type
}
func (e *UnsupportedTypeError) Is(err error) bool {
//goland:noinspection GoTypeAssertionOnErrors
t, ok := err.(*UnsupportedTypeError)
return ok && e.Type == t.Type
}
func (e *UnsupportedTypeError) Error() string {
return "type `" + e.Type.String() + "` is not supported"
}
const (
ErrParseFailure errors.Msg = "failed to parse"
ErrValidationFailure errors.Msg = "failed to validate"
)
func errKind(err error) error {
var numErr *strconv.NumError
if errors.As(err, &numErr) {
if errors.Is(numErr.Err, strconv.ErrRange) {
return ErrValidationFailure
} else {
return ErrParseFailure
}
}
return nil
}