/
errors.go
50 lines (39 loc) · 1.53 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
package main
import (
"errors"
"fmt"
)
var (
errNotFound = errors.New("not found")
errInvalidArgument = errors.New("invalid argument")
errInvalidOperation = errors.New("invalid operation")
errFailed = errors.New("failed")
errUnsupported = errors.New("unsupported")
)
func ErrUnsupported(what string, value interface{}) error {
return fmt.Errorf("%s=%v %w", what, value, errUnsupported)
}
func ErrNotFound(what string) error {
return fmt.Errorf("%s %w", what, errNotFound)
}
func ErrNotFoundWithParam(what string, paramName string, paramValue interface{}) error {
return fmt.Errorf("%s %w with %s=%v", what, errNotFound, paramName, paramValue)
}
func ErrInvalidOperation(operation interface{}) error {
return fmt.Errorf("%w: %v", errInvalidOperation, operation)
}
func ErrInvalidArgument(name string, value interface{}) error {
return fmt.Errorf("%w '%s': %v", errInvalidArgument, name, value)
}
func ErrInvalidArgumentWithReason(name string, value interface{}, reason string) error {
return fmt.Errorf("%w '%s'=%v (%s)", errInvalidArgument, name, value, reason)
}
func ErrOperationFailed(operation interface{}) error {
return fmt.Errorf("%v %w", operation, errFailed)
}
func ErrOperationFailedWithReason(operation interface{}, reason string) error {
return fmt.Errorf("%v %w due to: : %s", operation, errFailed, reason)
}
func ErrOperationFailedWithParam(operation interface{}, paramName string, paramValue interface{}) error {
return fmt.Errorf("'%v' %w for %s=%v", operation, errFailed, paramName, paramValue)
}