-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
135 lines (106 loc) · 2.62 KB
/
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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Author: fasion
* Created time: 2022-11-02 21:47:37
* Last Modified by: fasion
* Last Modified time: 2023-12-21 17:11:28
*/
package baseutils
import (
"fmt"
"reflect"
"github.com/fasionchan/goutils/stl"
)
type GenericNotFoundError struct {
t string
name string
}
func NewGenericNotFoundError(t, name string) GenericNotFoundError {
return GenericNotFoundError{
t: t,
name: name,
}
}
func (e GenericNotFoundError) Name() string {
return e.name
}
func (e GenericNotFoundError) Type() string {
return e.t
}
func (e GenericNotFoundError) Error() string {
return fmt.Sprintf("%s not found: %s", e.Type(), e.Name())
}
type EnvironmentVariableNotFoundError struct {
name string
}
func NewEnvironmentVariableNotFoundError(name string) EnvironmentVariableNotFoundError {
return EnvironmentVariableNotFoundError{
name: name,
}
}
func (e EnvironmentVariableNotFoundError) Name() string {
return e.name
}
func (e EnvironmentVariableNotFoundError) Error() string {
return fmt.Sprintf("environment variable not found: %s", e.name)
}
type CookieNotFoundError struct {
name string
}
func NewCookieNotFoundError(name string) CookieNotFoundError {
return CookieNotFoundError{
name: name,
}
}
func (e CookieNotFoundError) Name() string {
return e.name
}
func (e CookieNotFoundError) Error() string {
return fmt.Sprintf("cookie not found: %s", e.name)
}
type NotImplementedError struct {
hint string
}
func NewNotImplementedError(hint string) NotImplementedError {
return NotImplementedError{
hint: hint,
}
}
func (e NotImplementedError) Error() string {
return fmt.Sprintf("not implemented: %s", e.hint)
}
type BadTypeError struct {
expected string
given string
}
func NewBlankBadTypeError() BadTypeError {
return BadTypeError{}
}
func NewBadTypeError(expected, given string) BadTypeError {
return BadTypeError{
expected: expected,
given: given,
}
}
func (err BadTypeError) WithExpected(expected string) BadTypeError {
err.expected = expected
return err
}
func (err BadTypeError) WithExpectedReflectType(expected reflect.Type) BadTypeError {
err.expected = expected.String()
return err
}
func (err BadTypeError) WithGiven(given string) BadTypeError {
err.given = given
return err
}
func (err BadTypeError) WithGivenReflectType(given reflect.Type) BadTypeError {
err.given = given.String()
return err
}
func NewBadTypeErrorWithGivenReflectType(expected, given reflect.Type) BadTypeError {
return NewBadTypeError(expected.String(), given.String())
}
func (e BadTypeError) Error() string {
return fmt.Sprintf("bad type error: [%s] expected, but given [%s]", e.expected, e.given)
}
type Errors = stl.Errors