-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
84 lines (68 loc) · 1.64 KB
/
Copy patherrors.go
File metadata and controls
84 lines (68 loc) · 1.64 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
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
package option
import (
"fmt"
)
// DecodeError is returned when decoding failed due to invalid code in msgpack stream.
type DecodeError struct {
Type string
Code Byte
Parent error
}
// Error returns the text representation of error.
func (d DecodeError) Error() string {
if d.Code.IsSome() {
return fmt.Sprintf("failed to decode %s, invalid code: %d", d.Type, d.Code.Unwrap())
}
return fmt.Sprintf("failed to decode %s: %s", d.Type, d.Parent)
}
func newDecodeWithCodeError(operationType string, code byte) error {
return DecodeError{
Type: operationType,
Code: SomeByte(code),
Parent: nil,
}
}
func getGenericTypeName[T any]() string {
return fmt.Sprintf("Generic[%T]", zero[T]())
}
func newDecodeError(operationType string, err error) error {
if err == nil {
return nil
}
return DecodeError{
Type: operationType,
Code: NoneByte(),
Parent: err,
}
}
func newDecodeGenericError[T any](err error) error {
if err == nil {
return nil
}
return DecodeError{
Type: getGenericTypeName[T](),
Code: NoneByte(),
Parent: err,
}
}
// EncodeError is returned when encoding failed due to stream errors.
type EncodeError struct {
Type string
Parent error
}
// Error returns the text representation of error.
func (e EncodeError) Error() string {
return fmt.Sprintf("failed to encode %s: %s", e.Type, e.Parent)
}
func newEncodeError(operationType string, err error) error {
if err == nil {
return nil
}
return EncodeError{Type: operationType, Parent: err}
}
func newEncodeGenericError[T any](err error) error {
if err == nil {
return nil
}
return EncodeError{Type: getGenericTypeName[T](), Parent: err}
}