| 241 | } |
| 242 | |
| 243 | func (r *Runner) decodePosFromBody(body hcl.Body) (hcl.Pos, hcl.Diagnostics) { |
| 244 | pos := hcl.Pos{} |
| 245 | var diags hcl.Diagnostics |
| 246 | |
| 247 | posBody, moreDiags := body.Content(testFilePosSchema) |
| 248 | diags = append(diags, moreDiags...) |
| 249 | |
| 250 | if attr, ok := posBody.Attributes["line"]; ok { |
| 251 | val, moreDiags := attr.Expr.Value(nil) |
| 252 | diags = append(diags, moreDiags...) |
| 253 | |
| 254 | if !moreDiags.HasErrors() { |
| 255 | if err := gocty.FromCtyValue(val, &pos.Line); err != nil { |
| 256 | diags = diags.Append(&hcl.Diagnostic{ |
| 257 | Severity: hcl.DiagError, |
| 258 | Summary: "Invalid line number", |
| 259 | Detail: fmt.Sprintf("The line number must be an integer: %s", err), |
| 260 | Subject: posBody.Attributes["line"].Expr.Range().Ptr(), |
| 261 | }) |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | if attr, ok := posBody.Attributes["column"]; ok { |
| 267 | val, moreDiags := attr.Expr.Value(nil) |
| 268 | diags = append(diags, moreDiags...) |
| 269 | |
| 270 | if !moreDiags.HasErrors() { |
| 271 | if err := gocty.FromCtyValue(val, &pos.Column); err != nil { |
| 272 | diags = diags.Append(&hcl.Diagnostic{ |
| 273 | Severity: hcl.DiagError, |
| 274 | Summary: "Invalid column number", |
| 275 | Detail: fmt.Sprintf("The column number must be an integer: %s", err), |
| 276 | Subject: posBody.Attributes["column"].Expr.Range().Ptr(), |
| 277 | }) |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | if attr, ok := posBody.Attributes["byte"]; ok { |
| 283 | val, moreDiags := attr.Expr.Value(nil) |
| 284 | diags = append(diags, moreDiags...) |
| 285 | |
| 286 | if !moreDiags.HasErrors() { |
| 287 | if err := gocty.FromCtyValue(val, &pos.Byte); err != nil { |
| 288 | diags = diags.Append(&hcl.Diagnostic{ |
| 289 | Severity: hcl.DiagError, |
| 290 | Summary: "Invalid byte position", |
| 291 | Detail: fmt.Sprintf("The byte position must be an integer: %s", err), |
| 292 | Subject: posBody.Attributes["byte"].Expr.Range().Ptr(), |
| 293 | }) |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | return pos, diags |
| 299 | } |
| 300 | |