MCPcopy
hub / github.com/hashicorp/hcl / decodeDiagnosticsBlock

Method decodeDiagnosticsBlock

cmd/hclspecsuite/test_file.go:193–241  ·  cmd/hclspecsuite/test_file.go::Runner.decodeDiagnosticsBlock
(block *hcl.Block)

Source from the content-addressed store, hash-verified

191}
192
193func (r *Runner) decodeDiagnosticsBlock(block *hcl.Block) ([]*TestFileExpectDiag, hcl.Diagnostics) {
194 var diags hcl.Diagnostics
195
196 content, moreDiags := block.Body.Content(testFileDiagnosticsSchema)
197 diags = append(diags, moreDiags...)
198 if moreDiags.HasErrors() {
199 return nil, diags
200 }
201
202 if len(content.Blocks) == 0 {
203 diags = diags.Append(&hcl.Diagnostic{
204 Severity: hcl.DiagError,
205 Summary: "Empty diagnostics block",
206 Detail: "If a diagnostics block is present, at least one expectation statement (\"error\" or \"warning\" block) must be included.",
207 Subject: &block.TypeRange,
208 })
209 return nil, diags
210 }
211
212 ret := make([]*TestFileExpectDiag, 0, len(content.Blocks))
213 for _, block := range content.Blocks {
214 rng, remain, moreDiags := r.decodeRangeFromBody(block.Body)
215 diags = append(diags, moreDiags...)
216 if diags.HasErrors() {
217 continue
218 }
219
220 // Should have nothing else in the block aside from the range definition.
221 _, moreDiags = remain.Content(&hcl.BodySchema{})
222 diags = append(diags, moreDiags...)
223
224 var severity hcl.DiagnosticSeverity
225 switch block.Type {
226 case "error":
227 severity = hcl.DiagError
228 case "warning":
229 severity = hcl.DiagWarning
230 default:
231 panic(fmt.Sprintf("unsupported block type %q", block.Type))
232 }
233
234 ret = append(ret, &TestFileExpectDiag{
235 Severity: severity,
236 Range: rng,
237 DeclRange: block.TypeRange,
238 })
239 }
240 return ret, diags
241}
242
243func (r *Runner) decodePosFromBody(body hcl.Body) (hcl.Pos, hcl.Diagnostics) {
244 pos := hcl.Pos{}

Callers 1

LoadTestFileMethod · 0.95

Calls 4

HasErrorsMethod · 0.95
AppendMethod · 0.95
decodeRangeFromBodyMethod · 0.95
ContentMethod · 0.65

Tested by

no test coverage detected