-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
47 lines (37 loc) · 1021 Bytes
/
errors.go
File metadata and controls
47 lines (37 loc) · 1021 Bytes
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
package puzzle
import "fmt"
type KeyAlreadyExistsError struct {
Key string
}
func (e *KeyAlreadyExistsError) Error() string {
return fmt.Sprintf("key %s already exists", e.Key)
}
type KeyNotFoundError struct {
Key string
}
func (e *KeyNotFoundError) Error() string {
return fmt.Sprintf("key %s not found", e.Key)
}
type TypeMismatchError struct {
Key string
RequestedType string
ActualType string
}
func newTypeMismatchError(key string, requested any, actual any) *TypeMismatchError {
return &TypeMismatchError{
Key: key,
RequestedType: fmt.Sprintf("%T", requested),
ActualType: fmt.Sprintf("%T", actual),
}
}
func (e *TypeMismatchError) Error() string {
return fmt.Sprintf("type mismatch for key %s: requested %s, got %s", e.Key, e.RequestedType, e.ActualType)
}
type InvalidValueError struct {
Key string
Value any
Err error
}
func (e *InvalidValueError) Error() string {
return fmt.Sprintf("invalid value for key %s: %v, error: %v", e.Key, e.Value, e.Err)
}