-
Notifications
You must be signed in to change notification settings - Fork 2
/
parse.go
173 lines (157 loc) · 5.36 KB
/
parse.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Use and distribution licensed under the Apache license version 2.
//
// See the COPYING file in the root project directory for full text.
package errors
import (
"errors"
"fmt"
"gopkg.in/yaml.v3"
)
var (
// ErrUnknownSourceType indicates that a From() function was called with an
// unknown source parameter type.
ErrUnknownSourceType = errors.New("unknown source argument type")
// ErrUnknownSpec indicates that there was a test spec definition in a YAML
// file that no plugin could parse.
ErrUnknownSpec = errors.New("no plugin could parse spec definition")
// ErrUnknownField indicates that there was an unknown field in the parsing
// of a spec or scenario.
ErrUnknownField = errors.New("unknown field")
// ErrParse indicates a YAML definition is not valid
ErrParse = errors.New("invalid YAML")
// ErrExpectedMap indicates that we did not find an expected mapping
// field
ErrExpectedMap = fmt.Errorf(
"%w: expected map field", ErrParse,
)
// ErrExpectedScalar indicates that we did not find an expected scalar
// field
ErrExpectedScalar = fmt.Errorf(
"%w: expected scalar field", ErrParse,
)
// ErrExpectedSequence indicates that we did not find an expected
// scalar field
ErrExpectedSequence = fmt.Errorf(
"%w: expected sequence field", ErrParse,
)
// ErrExpectedInt indicates that we did not find an expected integer
// value
ErrExpectedInt = fmt.Errorf(
"%w: expected int value", ErrParse,
)
// ErrExpectedScalarOrMap indicates that we did not find an expected
// scalar or map field
ErrExpectedScalarOrMap = fmt.Errorf(
"%w: expected scalar or map field", ErrParse,
)
// ErrExpectedScalarOrSequence indicates that we did not find an expected
// scalar or sequence of scalars field
ErrExpectedScalarOrSequence = fmt.Errorf(
"%w: expected scalar or sequence of scalars field", ErrParse,
)
// ErrParseTimeout indicates that the timeout specification was not valid.
ErrExpectedTimeout = fmt.Errorf(
"%w: expected timeout specification", ErrParse,
)
// ErrParseWait indicates that the wait specification was not valid.
ErrExpectedWait = fmt.Errorf(
"%w: expected wait specification", ErrParse,
)
// ErrFileNotFound is returned when a file path does not exist for a
// create/apply/delete target.
ErrFileNotFound = fmt.Errorf(
"%w: file not found", ErrParse,
)
)
// UnknownSpecAt returns an ErrUnknownSpec with the line/column of the supplied
// YAML node.
func UnknownSpecAt(path string, node *yaml.Node) error {
return fmt.Errorf(
"%w in %s at line %d, column %d",
ErrUnknownSpec, path, node.Line, node.Column,
)
}
// UnknownFieldAt returns an ErrUnknownField for a supplied field annotated
// with the line/column of the supplied YAML node.
func UnknownFieldAt(field string, node *yaml.Node) error {
return fmt.Errorf(
"%w: %q at line %d, column %d",
ErrUnknownField, field, node.Line, node.Column,
)
}
// ExpectedMapAt returns an ErrExpectedMap error annotated with the
// line/column of the supplied YAML node.
func ExpectedMapAt(node *yaml.Node) error {
return fmt.Errorf(
"%w at line %d, column %d",
ErrExpectedMap, node.Line, node.Column,
)
}
// ExpectedScalarAt returns an ErrExpectedScalar error annotated with
// the line/column of the supplied YAML node.
func ExpectedScalarAt(node *yaml.Node) error {
return fmt.Errorf(
"%w at line %d, column %d",
ErrExpectedScalar, node.Line, node.Column,
)
}
// ExpectedSequenceAt returns an ErrExpectedSequence error annotated
// with the line/column of the supplied YAML node.
func ExpectedSequenceAt(node *yaml.Node) error {
return fmt.Errorf(
"%w at line %d, column %d",
ErrExpectedSequence, node.Line, node.Column,
)
}
// ExpectedIntAt returns an ErrExpectedInt error annotated
// with the line/column of the supplied YAML node.
func ExpectedIntAt(node *yaml.Node) error {
return fmt.Errorf(
"%w at line %d, column %d",
ErrExpectedInt, node.Line, node.Column,
)
}
// ExpectedScalarOrSequenceAt returns an ErrExpectedScalarOrSequence error
// annotated with the line/column of the supplied YAML node.
func ExpectedScalarOrSequenceAt(node *yaml.Node) error {
return fmt.Errorf(
"%w at line %d, column %d",
ErrExpectedScalarOrSequence, node.Line, node.Column,
)
}
// ExpectedScalarOrMapAt returns an ErrExpectedScalarOrMap error annotated with
// the line/column of the supplied YAML node.
func ExpectedScalarOrMapAt(node *yaml.Node) error {
return fmt.Errorf(
"%w at line %d, column %d",
ErrExpectedScalarOrMap, node.Line, node.Column,
)
}
// ExpectedTimeoutAt returns an ErrExpectedTimeout error annotated
// with the line/column of the supplied YAML node.
func ExpectedTimeoutAt(node *yaml.Node) error {
return fmt.Errorf(
"%w at line %d, column %d",
ErrExpectedTimeout, node.Line, node.Column,
)
}
// ExpectedWaitAt returns an ErrExpectedWait error annotated with the
// line/column of the supplied YAML node.
func ExpectedWaitAt(node *yaml.Node) error {
return fmt.Errorf(
"%w at line %d, column %d",
ErrExpectedWait, node.Line, node.Column,
)
}
// UnknownSourceType returns an ErrUnknownSourceType error describing the
// supplied parameter type.
func UnknownSourceType(source interface{}) error {
return fmt.Errorf("%w: %T", ErrUnknownSourceType, source)
}
// FileNotFound returns ErrFileNotFound for a given file path
func FileNotFound(path string, node *yaml.Node) error {
return fmt.Errorf(
"%w: %s at line %d, column %d",
ErrFileNotFound, path, node.Line, node.Column,
)
}