-
Notifications
You must be signed in to change notification settings - Fork 0
/
profiles_errors.go
75 lines (61 loc) · 2.15 KB
/
profiles_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
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
package launcher
import (
"errors"
"fmt"
)
// IllegalDimensionsNumberError is an error that is reported when the dimensions number does not meet or exceeds allowed
// range (that is 2 dimensions - width and height).
type IllegalDimensionsNumberError struct {
Count int // The number of dimensions found, or -1 if none
}
func (e *IllegalDimensionsNumberError) Error() string {
if e.Count == -1 {
return "no dimensions found"
} else {
return "too many dimensions"
}
}
func (e *IllegalDimensionsNumberError) Is(target error) bool {
t, ok := target.(*IllegalDimensionsNumberError)
return ok && (t.Count == 0 || e.Count == t.Count)
}
// IllegalDimensionValueError is an error that is reported when value for specific dimension is incorrect.
type IllegalDimensionValueError struct {
Value string // Value that cannot be processed
Dimension string // Either "width" or "height"
Err error // Parsing error, if any
}
func (e *IllegalDimensionValueError) Error() string {
if e.Err != nil {
return fmt.Sprintf("\"%s\" is illegal value for dimension %s: %s", e.Value, e.Dimension, e.Err)
} else {
return fmt.Sprintf("\"%s\" is illegal value for dimension %s", e.Value, e.Dimension)
}
}
func (e *IllegalDimensionValueError) Unwrap() error {
return e.Err
}
func (e *IllegalDimensionValueError) Is(target error) bool {
t, ok := target.(*IllegalDimensionValueError)
return ok &&
(t.Value == "" || e.Value == t.Value) &&
(t.Dimension == "" || e.Dimension == t.Dimension) &&
(t.Err == nil || errors.Is(e.Err, t.Err)) // FIXME: weak check (should only check top error)
}
// ResolutionParseError is an error that is reported when resolution cannot be parsed from string
type ResolutionParseError struct {
Input string
Err error
}
func (e *ResolutionParseError) Error() string {
return fmt.Sprintf("cannot parse resolution: %s", e.Err.Error())
}
func (e *ResolutionParseError) Is(target error) bool {
t, ok := target.(*ResolutionParseError)
return ok &&
(t.Err == nil || errors.Is(e.Err, t.Err)) && // FIXME: weak check (should only check top error)
(t.Input == "" || e.Input == t.Input)
}
func (e *ResolutionParseError) Unwrap() error {
return e.Err
}