opentofu/internal/tfdiags/simple_warning.go
Martin Atkins 8405f46bc5 tfdiags: Expose the "extra information" concept from HCL
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.
2022-06-23 13:52:23 -07:00

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
}