opentofu/internal/tfdiags/rpc_friendly.go
Martin Atkins 05caff2ca3 Move tfdiags/ to internal/tfdiags/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00

60 lines
1.2 KiB
Go

package tfdiags
import (
"encoding/gob"
)
type rpcFriendlyDiag struct {
Severity_ Severity
Summary_ string
Detail_ string
Subject_ *SourceRange
Context_ *SourceRange
}
// rpcFriendlyDiag transforms a given diagnostic so that is more friendly to
// RPC.
//
// In particular, it currently returns an object that can be serialized and
// later re-inflated using gob. This definition may grow to include other
// serializations later.
func makeRPCFriendlyDiag(diag Diagnostic) Diagnostic {
desc := diag.Description()
source := diag.Source()
return &rpcFriendlyDiag{
Severity_: diag.Severity(),
Summary_: desc.Summary,
Detail_: desc.Detail,
Subject_: source.Subject,
Context_: source.Context,
}
}
func (d *rpcFriendlyDiag) Severity() Severity {
return d.Severity_
}
func (d *rpcFriendlyDiag) Description() Description {
return Description{
Summary: d.Summary_,
Detail: d.Detail_,
}
}
func (d *rpcFriendlyDiag) Source() Source {
return Source{
Subject: d.Subject_,
Context: d.Context_,
}
}
func (d rpcFriendlyDiag) FromExpr() *FromExpr {
// RPC-friendly diagnostics cannot preserve expression information because
// expressions themselves are not RPC-friendly.
return nil
}
func init() {
gob.Register((*rpcFriendlyDiag)(nil))
}