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.
34 lines
667 B
Go
34 lines
667 B
Go
package tfdiags
|
|
|
|
// nativeError is a Diagnostic implementation that wraps a normal Go error
|
|
type nativeError struct {
|
|
err error
|
|
}
|
|
|
|
var _ Diagnostic = nativeError{}
|
|
|
|
func (e nativeError) Severity() Severity {
|
|
return Error
|
|
}
|
|
|
|
func (e nativeError) Description() Description {
|
|
return Description{
|
|
Summary: FormatError(e.err),
|
|
}
|
|
}
|
|
|
|
func (e nativeError) Source() Source {
|
|
// No source information available for a native error
|
|
return Source{}
|
|
}
|
|
|
|
func (e nativeError) FromExpr() *FromExpr {
|
|
// Native errors are not expression-related
|
|
return nil
|
|
}
|
|
|
|
func (e nativeError) ExtraInfo() interface{} {
|
|
// Native errors don't carry any "extra information".
|
|
return nil
|
|
}
|