mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
8405f46bc5
HCL's diagnostic model now includes the idea of "extra information" which works by attaching an initially-opaque interface value to each diagnostic and then asking callers to type-assert against that value to sniff for particular interfaces in order to discover additional machine-readable context about a certain diagnostic message. This commit echoes that idea into our tfdiags API, for now only for diagnostics that are backed by an hcl.Diagnostic. All other implementations of the diagnostic interface just always return nil, which means they never carry any "extra information". As is typical for our wrapping abstraction, we have here also a modified copy of HCL's helper function for conveniently probing a diagnostic for information of a particular type, designed to work with our diagnostic interface instead of HCL's concrete diagnostic type.
36 lines
733 B
Go
36 lines
733 B
Go
package tfdiags
|
|
|
|
type simpleWarning string
|
|
|
|
var _ Diagnostic = simpleWarning("")
|
|
|
|
// SimpleWarning constructs a simple (summary-only) warning diagnostic.
|
|
func SimpleWarning(msg string) Diagnostic {
|
|
return simpleWarning(msg)
|
|
}
|
|
|
|
func (e simpleWarning) Severity() Severity {
|
|
return Warning
|
|
}
|
|
|
|
func (e simpleWarning) Description() Description {
|
|
return Description{
|
|
Summary: string(e),
|
|
}
|
|
}
|
|
|
|
func (e simpleWarning) Source() Source {
|
|
// No source information available for a simple warning
|
|
return Source{}
|
|
}
|
|
|
|
func (e simpleWarning) FromExpr() *FromExpr {
|
|
// Simple warnings are not expression-related
|
|
return nil
|
|
}
|
|
|
|
func (e simpleWarning) ExtraInfo() interface{} {
|
|
// Simple warnings cannot carry extra information.
|
|
return nil
|
|
}
|