-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
86 lines (72 loc) · 2.91 KB
/
errors.go
File metadata and controls
86 lines (72 loc) · 2.91 KB
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
package puz
import (
"errors"
"fmt"
)
var (
OutOfBoundsReadError = errors.New("Out of bounds read")
OutOfBoundsWriteError = errors.New("Out of bounds write")
UnreadableDataError = errors.New("Data does not appear to represent a crossword puzzle")
MissingFileMagicError = errors.New("Failed to find ACROSS&DOWN string in file")
UnkownExtraSectionNameError = errors.New("Unknown extra section name")
MissingExtraSectionError = errors.New("An extra section was expected but not found")
BoardWidthMismatchError = errors.New("Board contains rows of unequal width")
PuzzleIsUnscrambledError = errors.New("Puzzle is already unscrambled")
PuzzleIsScrambledError = errors.New("Puzzle is already scrambled")
InvalidVersionFormatError = errors.New("Invalid version format, must be X.X")
TooFewCharactersToUnscrambleError = errors.New("Too few characters to unscramble, minimum 12")
TooFewCharactersToScrambleError = errors.New("Too few characters to scramble, minimum 12")
NonLetterCharactersInScrambleError = errors.New("Scramble operations can not be performed on grids with non-letter characters")
InvalidDigitInKeyError = errors.New("Key cannot contain any zeros")
InvalidKeyLengthError = errors.New("Key must be a 4-digit number")
IncorrectKeyProvidedError = errors.New("Failed to unscramble, incorrect key provided")
)
// Checksum Mismatch
type checksum int
const (
globalChecksum checksum = iota
cibChecksum
maskedLowChecksum
maskedHighChecksum
)
var checksumStrMap = map[checksum]string{
globalChecksum: "Global Checksum",
cibChecksum: "CIB Checksum",
maskedLowChecksum: "Masked Low Checksum",
maskedHighChecksum: "Masked High Checksum",
}
func (c checksum) String() string {
return checksumStrMap[c]
}
type ChecksumMismatchError struct {
expected int
calculated int
checksum checksum
}
func (e *ChecksumMismatchError) Error() string {
return fmt.Sprintf("%s mismatch: expected %d, calculated %d", e.checksum.String(), e.expected, e.calculated)
}
// Extra Section Checksum Mismatch
type ExtraSectionChecksumMismatchError struct {
expected uint16
calculated uint16
section ExtraSection
}
func (e *ExtraSectionChecksumMismatchError) Error() string {
return fmt.Sprintf("%s section checksum mismatch: expected %d, calculated %d", e.section.String(), e.expected, e.calculated)
}
// Clue Mismatch
type ClueCountMismatchError struct {
expected int
found int
}
func (e *ClueCountMismatchError) Error() string {
return fmt.Sprintf("The expected clue count did not match the number of clue: expected %d, found %d", e.expected, e.found)
}
// Duplicate Extra Section
type DuplicateExtraSectionError struct {
section ExtraSection
}
func (e *DuplicateExtraSectionError) Error() string {
return fmt.Sprintf("A duplicate %s section was found", e.section.String())
}