mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 00:41:27 -06:00
e309675853
The usual usage of diagnostics requires us to pass around source location information to everywhere that might generate a diagnostic, and that is always the best way to get the most precise diagnostic source locations. However, it's impractical to require source location information to be retained in every Terraform subsystem, and so this new idea of "contextual diagnostics" allows us to separate the generation of a diagnostic from the resolution of its source location, instead resolving the location information as a post-processing step once the call stack unwinds to a place where there is enough context to find it. This is necessarily a less precise approach than reading the source ranges directly from the configuration AST, but gives us an alternative to no diagnostics at all in portions of Terraform where full location information is not available. This is a best-effort sort of thing which will get as precise as it can but may return a range in a parent block if the precise location of a particular attribute cannot be found. Diagnostics that rely on this mechanism should include some other contextual information in the detail message to make up for any loss of precision that results.
28 lines
668 B
Go
28 lines
668 B
Go
package tfdiags
|
|
|
|
// diagnosticBase can be embedded in other diagnostic structs to get
|
|
// default implementations of Severity and Description. This type also
|
|
// has a default implementation of Source that returns no source location
|
|
// information, so embedders should generally override that method to
|
|
// return more useful results.
|
|
type diagnosticBase struct {
|
|
severity Severity
|
|
summary string
|
|
detail string
|
|
}
|
|
|
|
func (d diagnosticBase) Severity() Severity {
|
|
return d.severity
|
|
}
|
|
|
|
func (d diagnosticBase) Description() Description {
|
|
return Description{
|
|
Summary: d.summary,
|
|
Detail: d.detail,
|
|
}
|
|
}
|
|
|
|
func (d diagnosticBase) Source() Source {
|
|
return Source{}
|
|
}
|