Debian Codegraph @

internal/libyaml/testdata/errors.yaml

raw symbols SCIP
1 # Copyright 2025 The go-yaml Project Contributors
2 # SPDX-License-Identifier: Apache-2.0
3
4 # Error type tests
5 #
6 # Purpose: Tests YAML error types and their formatting
7 #
8 # Format: Test cases use type-as-key format:
9 # - test-type:
10 # name: Test case name
11 # from: input error data
12 # want: expected error string output
13 # also: unwrap # (optional) test that Unwrap() returns underlying error
14 #
15 # Test Types:
16 # load-error - Tests LoadError formatting with different stages
17 # emitter-error - Tests EmitterError formatting (dump stack)
18 # writer-error - Tests WriterError formatting and Unwrap (dump stack)
19 # load-errors - Tests LoadErrors formatting
20 # load-errors-as - Tests LoadErrors.As method
21 # load-errors-is - Tests LoadErrors.Is method
22 # type-error - Tests deprecated TypeError formatting
23
24 # LoadError tests - different stages
25
26 - load-error:
27 name: Reader stage error
28 from:
29 stage: reader
30 mark:
31 line: 1
32 column: 3
33 index: 2
34 message: 'invalid UTF-8 octet (value: 255)'
35 err: invalid UTF-8 octet
36 want: 'go-yaml load error in reader at L1.C3: invalid UTF-8 octet (value: 255)'
37 also: unwrap
38
39 - load-error:
40 name: Scanner stage error
41 from:
42 stage: scanner
43 mark:
44 line: 2
45 column: 6
46 index: 42
47 message: unexpected token
48 want: 'go-yaml load error in scanner at L2.C6: unexpected token'
49
50 - load-error:
51 name: Scanner stage error with context
52 from:
53 stage: scanner
54 context_mark:
55 line: 2
56 column: 0
57 index: 20
58 context_message: while scanning a block scalar
59 mark:
60 line: 4
61 column: 9
62 index: 60
63 message: found unexpected end of stream
64 want: 'go-yaml load error in scanner (while scanning a block scalar) at L2-L4.C9: found unexpected end of stream'
65
66 - load-error:
67 name: Parser stage error
68 from:
69 stage: parser
70 mark:
71 line: 3
72 column: 11
73 index: 50
74 message: did not find expected key
75 want: 'go-yaml load error in parser at L3.C11: did not find expected key'
76
77 - load-error:
78 name: Parser stage error with context
79 from:
80 stage: parser
81 context_mark:
82 line: 1
83 column: 0
84 index: 0
85 context_message: while parsing a block mapping
86 mark:
87 line: 4
88 column: 6
89 index: 80
90 message: did not find expected key
91 want: 'go-yaml load error in parser (while parsing a block mapping) at L1-L4.C6: did not find expected key'
92
93 - load-error:
94 name: Composer stage error
95 from:
96 stage: composer
97 mark:
98 line: 1
99 column: 5
100 index: 4
101 message: unknown anchor 'foo' referenced
102 want: "go-yaml load error in composer at L1.C5: unknown anchor 'foo' referenced"
103
104 - load-error:
105 name: Resolver stage error
106 from:
107 stage: resolver
108 mark:
109 line: 1
110 column: 0
111 index: 0
112 message: cannot construct !!str `error` as a !!float
113 want: 'go-yaml load error in resolver at L1: cannot construct !!str `error` as a !!float'
114
115 - load-error:
116 name: Constructor stage error
117 from:
118 stage: constructor
119 mark:
120 line: 1
121 column: 0
122 index: 0
123 message: cannot construct !!map into string
124 err: cannot construct !!map into string
125 want: 'go-yaml load error in constructor at L1: cannot construct !!map into string'
126 also: unwrap
127
128 - load-error:
129 name: Constructor stage error at unknown position
130 from:
131 stage: constructor
132 message: cannot construct value
133 err: cannot construct value
134 want: 'go-yaml load error in constructor at <unknown position>: cannot construct value'
135 also: unwrap
136
137 # DumpError tests - dump stages
138
139 - dump-error:
140 name: Representer stage error
141 from:
142 stage: representer
143 message: cannot represent type chan int
144 want: 'go-yaml dump error in representer: cannot represent type chan int'
145
146 - dump-error:
147 name: Representer stage error with cause
148 from:
149 stage: representer
150 message: 'MarshalYAML failed: some error'
151 err: 'some error'
152 want: "go-yaml dump error in representer: MarshalYAML failed: some error"
153 also: unwrap
154
155 - dump-error:
156 name: Serializer stage error
157 from:
158 stage: serializer
159 message: cannot represent node with unknown kind 99
160 want: 'go-yaml dump error in serializer: cannot represent node with unknown kind 99'
161
162 - dump-error:
163 name: Emitter stage error
164 from:
165 stage: emitter
166 message: expected STREAM-START
167 want: 'go-yaml dump error in emitter: expected STREAM-START'
168
169 - dump-error:
170 name: Writer stage error with cause
171 from:
172 stage: writer
173 message: write error
174 err: write error
175 want: 'go-yaml dump error in writer: write error'
176 also: unwrap
177
178 # EmitterError tests (dump stack)
179
180 - emitter-error:
181 name: Basic emitter error
182 from:
183 message: expected STREAM-START
184 want: 'yaml: expected STREAM-START'
185
186 # WriterError tests (dump stack)
187
188 - writer-error:
189 name: Writer error with unwrap
190 from:
191 message: write error
192 want: 'yaml: write error'
193 also: unwrap
194
195 # LoadErrors tests
196
197 - load-errors:
198 name: Single error
199 from:
200 errors:
201 - line: 3
202 message: field not found
203 want: 'yaml: construct errors: line 3: field not found'
204
205 - load-errors:
206 name: Multiple errors
207 from:
208 errors:
209 - line: 5
210 message: field 'foo' not found in type struct
211 - line: 8
212 message: field 'bar' not found in type struct
213 want: "yaml: construct errors: line 5: field 'foo' not found in type struct; line 8: field 'bar' not found in type struct"
214
215 - load-errors:
216 name: Error at unknown position
217 from:
218 errors:
219 - line: 0
220 message: unknown field
221 want: 'yaml: construct errors: <unknown position>: unknown field'
222
223 # LoadErrors.As tests
224
225 - load-errors-as:
226 name: As TypeError
227 from:
228 errors:
229 - line: 3
230 message: first error
231 - line: 7
232 message: second error
233 as: TypeError
234 want_as: true
235 want_messages:
236 - 'line 3: first error'
237 - 'line 7: second error'
238
239 # LoadErrors.Is tests
240
241 - load-errors-is:
242 name: Contains error
243 from:
244 errors:
245 - line: 5
246 message: target error
247 is: target error
248 want_is: true
249
250 - load-errors-is:
251 name: Does not contain error
252 from:
253 errors:
254 - line: 5
255 message: different error
256 is: target error
257 want_is: false
258
259 # TypeError tests (backward compatibility)
260
261 - type-error:
262 name: Single type error
263 from:
264 errors:
265 - field not found
266 want: 'yaml: unmarshal errors: field not found'
267
268 - type-error:
269 name: Multiple type errors
270 from:
271 errors:
272 - 'line 3: first error'
273 - 'line 5: second error'
274 want: 'yaml: unmarshal errors: line 3: first error; line 5: second error'