mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
503c413de2
Add an address argument to tfdiags.InConfigBody, and store the address string the diagnostics details. Since nearly every place where we want to annotate the diagnostics with the config context we also have some sort of address, we can use the same call to insert them both into the diagnostic. Perhaps we should rename InConfigBody and ElaborateFromConfigBody to reflect the additional address parameter, but for now we can verify this is a pattern that suits us.
42 lines
723 B
Go
42 lines
723 B
Go
package tfdiags
|
|
|
|
import (
|
|
"github.com/hashicorp/hcl/v2"
|
|
)
|
|
|
|
type Diagnostic interface {
|
|
Severity() Severity
|
|
Description() Description
|
|
Source() Source
|
|
|
|
// FromExpr returns the expression-related context for the diagnostic, if
|
|
// available. Returns nil if the diagnostic is not related to an
|
|
// expression evaluation.
|
|
FromExpr() *FromExpr
|
|
}
|
|
|
|
type Severity rune
|
|
|
|
//go:generate go run golang.org/x/tools/cmd/stringer -type=Severity
|
|
|
|
const (
|
|
Error Severity = 'E'
|
|
Warning Severity = 'W'
|
|
)
|
|
|
|
type Description struct {
|
|
Address string
|
|
Summary string
|
|
Detail string
|
|
}
|
|
|
|
type Source struct {
|
|
Subject *SourceRange
|
|
Context *SourceRange
|
|
}
|
|
|
|
type FromExpr struct {
|
|
Expression hcl.Expression
|
|
EvalContext *hcl.EvalContext
|
|
}
|