-
Notifications
You must be signed in to change notification settings - Fork 17
/
errors.go
71 lines (54 loc) · 2.48 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package hocon
import "fmt"
// ParseError represents an error occurred while parsing a resource or string to a hocon configuration
type ParseError struct {
errType string
message string
line int
column int
}
func (p *ParseError) Error() string {
return fmt.Sprintf("%s at: %d:%d, %s", p.errType, p.line, p.column, p.message)
}
func parseError(errType, message string, line, column int) *ParseError {
return &ParseError{errType: errType, message: message, line: line, column: column}
}
func leadingPeriodError(line, column int) *ParseError {
return parseError("leading period '.'", `(use quoted "" empty string if you want an empty element)`, line, column)
}
func trailingPeriodError(line, column int) *ParseError {
return parseError("trailing period '.'", `(use quoted "" empty string if you want an empty element)`, line, column)
}
func adjacentPeriodsError(line, column int) *ParseError {
return parseError("two adjacent periods '.'", `(use quoted "" empty string if you want an empty element)`, line, column)
}
func invalidSubstitutionError(message string, line, column int) *ParseError {
return parseError("invalid substitution!", message, line, column)
}
func invalidArrayError(message string, line, column int) *ParseError {
return parseError("invalid config array!", message, line, column)
}
func invalidObjectError(message string, line, column int) *ParseError {
return parseError("invalid config object!", message, line, column)
}
func invalidKeyError(key string, line, column int) *ParseError {
return parseError("invalid key!", fmt.Sprintf("%q is a forbidden character in keys", key), line, column)
}
func invalidValueError(message string, line, column int) *ParseError {
return parseError("invalid value!", message, line, column)
}
func unclosedMultiLineStringError() *ParseError {
return parseError("unclosed multi-line string!", "", 0, 0)
}
func missingCommaError(line, column int) *ParseError {
return parseError("missing comma!", `values should have comma or ASCII newline ('\n') between them`, line, column)
}
func adjacentCommasError(line, column int) *ParseError {
return parseError("two adjacent commas", "adjacent commas in arrays and objects are invalid!", line, column)
}
func leadingCommaError(line, column int) *ParseError {
return parseError("leading comma", "leading comma in arrays and objects are invalid!", line, column)
}
func invalidConcatenationError() *ParseError {
return parseError("invalid concatenation!", "objects cannot be concatenated with other types", 0, 0)
}