-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy patherrors.go
More file actions
95 lines (73 loc) · 3.23 KB
/
Copy patherrors.go
File metadata and controls
95 lines (73 loc) · 3.23 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
87
88
89
90
91
92
93
94
95
package hocon
import (
"errors"
"fmt"
)
// ErrPathNotFound is the error returned by the Get*E methods when there is no value
// at the given path, it can be checked with errors.Is
var ErrPathNotFound = errors.New("path not found")
func pathNotFoundError(path string) error {
return fmt.Errorf("%w: %q", ErrPathNotFound, path)
}
func cannotParseError(value Value, targetType string) error {
return fmt.Errorf("cannot parse value: %s to %s!", value, targetType)
}
// 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 invalidKeyValueSeparatorError(key, token string, line, column int) *ParseError {
got := fmt.Sprintf("%q", token)
if token == "" {
got = "end of file"
}
return parseError("invalid key-value separator!", fmt.Sprintf("expected ':', '=', '{' or '+=' after the key %q, got: %s", key, got), 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!", "arrays and objects cannot be concatenated with other types", 0, 0)
}