From 7550624238512f1aedc608ee93b0deb8b8f18bb6 Mon Sep 17 00:00:00 2001 From: Anton Tayanovskyy Date: Fri, 27 Dec 2024 13:31:53 -0500 Subject: [PATCH] fix: remove rpc_friendly.go (#2800) Vendoring opentofu/tfdiags/rpc_friendly.go is not strictly needed but caused issues with encoding/gob such as the one in the referenced issue. Fixes https://github.com/pulumi/pulumi-terraform-bridge/issues/2784 --- pkg/vendored/generate.go | 21 +++--- pkg/vendored/opentofu/tfdiags/diagnostics.go | 7 -- pkg/vendored/opentofu/tfdiags/rpc_friendly.go | 70 ------------------- 3 files changed, 13 insertions(+), 85 deletions(-) delete mode 100755 pkg/vendored/opentofu/tfdiags/rpc_friendly.go diff --git a/pkg/vendored/generate.go b/pkg/vendored/generate.go index ffd754afd..279d8edd0 100644 --- a/pkg/vendored/generate.go +++ b/pkg/vendored/generate.go @@ -236,11 +236,6 @@ func vendorOpenTOFU(version string) { dest: "tfdiags/diagnostic_base.go", transforms: transforms, }, - { - src: "internal/tfdiags/rpc_friendly.go", - dest: "tfdiags/rpc_friendly.go", - transforms: transforms, - }, { src: "internal/tfdiags/contextual.go", dest: "tfdiags/contextual.go", @@ -271,9 +266,19 @@ func vendorOpenTOFU(version string) { }), }, { - src: "internal/tfdiags/diagnostics.go", - dest: "tfdiags/diagnostics.go", - transforms: transforms, + src: "internal/tfdiags/diagnostics.go", + dest: "tfdiags/diagnostics.go", + transforms: append(transforms, func(s string) string { + code := `func (diags Diagnostics) ForRPC() Diagnostics { + ret := make(Diagnostics, len(diags)) + for i := range diags { + ret[i] = makeRPCFriendlyDiag(diags[i]) + } + return ret +} +` + return strings.ReplaceAll(s, code, "") + }), }, { src: "internal/tfdiags/sourceless.go", diff --git a/pkg/vendored/opentofu/tfdiags/diagnostics.go b/pkg/vendored/opentofu/tfdiags/diagnostics.go index 0fba45093..e92f1fe6d 100755 --- a/pkg/vendored/opentofu/tfdiags/diagnostics.go +++ b/pkg/vendored/opentofu/tfdiags/diagnostics.go @@ -123,13 +123,6 @@ func (diags Diagnostics) HasErrors() bool { // Note that this loses information about the original objects used to // construct the diagnostics, so e.g. the errwrap API will not work as // expected on an error-wrapped Diagnostics that came from ForRPC. -func (diags Diagnostics) ForRPC() Diagnostics { - ret := make(Diagnostics, len(diags)) - for i := range diags { - ret[i] = makeRPCFriendlyDiag(diags[i]) - } - return ret -} // Err flattens a diagnostics list into a single Go error, or to nil // if the diagnostics list does not include any error-level diagnostics. diff --git a/pkg/vendored/opentofu/tfdiags/rpc_friendly.go b/pkg/vendored/opentofu/tfdiags/rpc_friendly.go deleted file mode 100755 index d7448b0f8..000000000 --- a/pkg/vendored/opentofu/tfdiags/rpc_friendly.go +++ /dev/null @@ -1,70 +0,0 @@ -// Code copied from github.com/opentofu/opentofu by go generate; DO NOT EDIT. -// Copyright (c) The OpenTofu Authors -// SPDX-License-Identifier: MPL-2.0 -// Copyright (c) 2023 HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -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 (d rpcFriendlyDiag) ExtraInfo() interface{} { - // RPC-friendly diagnostics always discard any "extra information". - return nil -} - -func init() { - gob.Register((*rpcFriendlyDiag)(nil)) -}