-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
41 lines (32 loc) · 1.32 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
package balance
import "fmt"
// MismatchError is returned when given string has a mismatched parentheses at index.
type MismatchError struct {
Index int // index is position of mismatched parentheses
}
func (e *MismatchError) Error() string {
return fmt.Sprintf("Mismatch at index: %d", e.Index)
}
// UnknownCharacterError is returned when given string has a unknown character rune at index.
type UnknownCharacterError struct {
Index int // index is position of unknown character
Char rune // char is unknown character
}
func (e *UnknownCharacterError) Error() string {
return fmt.Sprintf("Unknown character %q at index: %d", e.Char, e.Index)
}
// UnclosedParenthesesError is returned when given string has a unclosed parentheses at index.
type UnclosedParenthesesError struct {
Count int // count is number of unclosed parentheses
}
func (e *UnclosedParenthesesError) Error() string {
return fmt.Sprintf("Unclosed %d parentheses", e.Count)
}
// CustomPairError is returned when given custom pair strings has different lengths.
type CustomPairError struct {
Opens string // opens is opening elements that has error
Closes string // closes is closings elements that has error
}
func (e *CustomPairError) Error() string {
return fmt.Sprintf("Custom pair strings should have same length. Opens: %q Closes: %q", e.Opens, e.Closes)
}