Skip to content

Commit d1eb4c3

Browse files
committed
errors: migrate from gogo/protobuf to google.golang.org/protobuf
github.com/gogo/protobuf, along with the related github.com/gogo/status and github.com/gogo/googleapis, is deprecated and unmaintained. This migrates the whole module to the standard, maintained protobuf stack it already depended on: google.golang.org/protobuf (+ anypb), google.golang.org/grpc/status, and google.golang.org/genproto/googleapis/rpc/status. The .proto files are regenerated with the standard protoc-gen-go and protoc-gen-go-grpc, dropping the custom protoc-gen-gogoroach plugin and all gogoproto options, and the hand-written code is adapted to the v2 runtime: - errbase packs and unpacks error detail payloads with anypb.New and (*anypb.Any).UnmarshalNew, resolving types through the standard protoregistry instead of gogo's registry. - The previously non-nullable embedded fields (Details, Cause, ErrorTypeMark) are now pointers, read through the generated nil-safe getters. DecodeError takes *EncodedError and GetTypeMark returns *errorspb.ErrorTypeMark accordingly. - extgrpc and grpc/middleware use google.golang.org/grpc/status. Because the standard Any can hold standard protobufs directly, the former gogo/standard status split collapses into a single path, and google.rpc.Status now comes from genproto with the same type URL. - go.mod drops all three gogo modules. Wire compatibility is preserved: no proto package/message name or field number changes, and google.protobuf.Any type URLs are unchanged, so errors serialized by the previous gogo-based version still decode here and vice versa. This is a breaking API change (major version): the encoder/decoder registration interfaces now reference the v2 proto.Message, so consumers that register custom error types must supply standard-protobuf payloads. Errors originally produced as github.com/gogo/status types decode to an opaque error (message and safe details preserved) rather than being reconstructed as a gRPC status. Signed-off-by: Liran Funaro <liran.funaro@gmail.com>
1 parent 4fc17f8 commit d1eb4c3

81 files changed

Lines changed: 11639 additions & 8155 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile.update-protos

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
1-
# This makefile can be used to-regenerate the protobuf files.
1+
# This makefile can be used to regenerate the protobuf files.
22
#
33
# Prerequisites:
4-
# "protoc" from https://github.com/protocolbuffers/protobuf
5-
# go get github.com/cockroachdb/protoc-gen-gogoroach
6-
# go get github.com/gogo/protobuf/types
7-
# go get github.com/gogo/protobuf/protoc-gen-gogo
4+
# protoc https://github.com/protocolbuffers/protobuf
5+
# protoc-gen-go go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
6+
# protoc-gen-go-grpc go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
87
#
9-
# Note: as of 2021-04-13, we like to use a custom protoc-gen-gogo
10-
# with additional options, to stabilize the marshalled
11-
# encoding of objects (so that they are deterministic
12-
# across marshal/unmarshal cycles) and reduce the memory footprint
13-
# of objects:
8+
# Run: make -f Makefile.update-protos
149
#
15-
# vanity.TurnOnStable_MarshalerAll,
16-
# vanity.TurnOffGoUnrecognizedAll,
17-
# vanity.TurnOffGoUnkeyedAll,
18-
# vanity.TurnOffGoSizecacheAll,
19-
#
20-
# Until this is resolved, the "go get" commands above are not
21-
# adequate; instead:
22-
#
23-
# 1. set the PATH env var to point to CockroachDB's `bin`
24-
# sub-directory (after a successful CockroachDB build), where a
25-
# suitable version of protoc-gen-gogoroach is provided.
26-
#
27-
# 2. run `make -f Makefile.update-protos` with this PATH active.
28-
29-
export SHELL := env PWD=$(CURDIR) bash
10+
# Note: the standard protoc-gen-go runtime always embeds state/sizeCache/
11+
# unknownFields per message and has no equivalent of the old gogo vanity
12+
# options. These messages have no map fields, so proto.Marshal output is
13+
# already byte-stable across marshal/unmarshal cycles (add
14+
# proto.MarshalOptions{Deterministic: true} if a map field is ever added).
15+
# The gogo memory-footprint trimming has no standard equivalent.
3016

3117
PROTOS := $(wildcard \
3218
errbase/internal/*.proto \
@@ -38,25 +24,9 @@ PROTOS := $(wildcard \
3824
)
3925
GO_SOURCES = $(PROTOS:.proto=.pb.go)
4026

41-
SED = sed
42-
SED_INPLACE := $(shell $(SED) --version 2>&1 | grep -q GNU && echo -i || echo "-i ''")
43-
44-
all: $(PROTOS)
45-
set -e; for dir in $(sort $(dir $(PROTOS))); do \
46-
protoc \
47-
-I. \
48-
-I$$GOPATH/src/ \
49-
-I$$GOPATH/src/github.com \
50-
-I$$GOPATH/src/github.com/cockroachdb/errors \
51-
-I$$GOPATH/src/github.com/gogo/protobuf \
52-
-I$$GOPATH/src/github.com/gogo/protobuf/protobuf \
53-
--gogoroach_out=Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,plugins=grpc,import_prefix=:. \
54-
$$dir/*.proto; \
55-
done
56-
$(SED) $(SED_INPLACE) -E \
57-
-e '/import _ /d' \
58-
-e 's!import (fmt|math) "github.com/(fmt|math)"! !g' \
59-
-e 's!github.com/((bytes|encoding/binary|errors|fmt|io|math|github\.com|(google\.)?golang\.org)([^a-z]|$$))!\1!g' \
60-
-e 's!golang.org/x/net/context!context!g' \
61-
$(GO_SOURCES)
27+
all:
28+
protoc -I. \
29+
--go_out=. --go_opt=paths=source_relative \
30+
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
31+
$(PROTOS)
6232
gofmt -s -w $(GO_SOURCES)

assert/assert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/cockroachdb/errors/errbase"
2222
"github.com/cockroachdb/errors/markers"
2323
"github.com/cockroachdb/errors/stdstrings"
24-
"github.com/gogo/protobuf/proto"
24+
"google.golang.org/protobuf/proto"
2525
)
2626

2727
// WithAssertionFailure decorates the error with an assertion failure marker.

assert/assert_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestAssert(t *testing.T) {
4545
tt.CheckEqual(err.Error(), "hello: world")
4646

4747
enc := errbase.EncodeError(context.Background(), err)
48-
newErr := errbase.DecodeError(context.Background(), enc)
48+
newErr := errbase.DecodeError(context.Background(), &enc)
4949

5050
tt.Check(markers.Is(newErr, baseErr))
5151

barriers/barriers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
"github.com/cockroachdb/errors/errbase"
2222
"github.com/cockroachdb/redact"
23-
"github.com/gogo/protobuf/proto"
23+
"google.golang.org/protobuf/proto"
2424
)
2525

2626
// Handled swallows the provided error and hides it from the
@@ -123,13 +123,13 @@ func encodeBarrier(
123123
// A barrier error is decoded exactly.
124124
func decodeBarrier(ctx context.Context, msg string, _ []string, payload proto.Message) error {
125125
enc := payload.(*errbase.EncodedError)
126-
return &barrierErr{smsg: redact.RedactableString(msg), maskedErr: errbase.DecodeError(ctx, *enc)}
126+
return &barrierErr{smsg: redact.RedactableString(msg), maskedErr: errbase.DecodeError(ctx, enc)}
127127
}
128128

129129
// Previous versions of barrier errors.
130130
func decodeBarrierPrev(ctx context.Context, msg string, _ []string, payload proto.Message) error {
131131
enc := payload.(*errbase.EncodedError)
132-
return &barrierErr{smsg: redact.Sprint(msg), maskedErr: errbase.DecodeError(ctx, *enc)}
132+
return &barrierErr{smsg: redact.Sprint(msg), maskedErr: errbase.DecodeError(ctx, enc)}
133133
}
134134

135135
// barrierError is the "old" type name of barrierErr. We use a new

barriers/barriers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TestBarrierMaskedDetails(t *testing.T) {
7575

7676
// Simulate a network traversal.
7777
enc := errbase.EncodeError(context.Background(), b)
78-
newB := errbase.DecodeError(context.Background(), enc)
78+
newB := errbase.DecodeError(context.Background(), &enc)
7979

8080
// The friends message is hidden.
8181
tt.Check(!strings.Contains(b.Error(), "friends"))

contexttags/contexttags_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestWithContext(t *testing.T) {
8383
tt.Run("local", func(tt testutils.T) { theTest(tt, decoratedErr) })
8484

8585
enc := errbase.EncodeError(context.Background(), decoratedErr)
86-
newErr := errbase.DecodeError(context.Background(), enc)
86+
newErr := errbase.DecodeError(context.Background(), &enc)
8787

8888
tt.Run("remote", func(tt testutils.T) { theTest(tt, newErr) })
8989
}
@@ -137,7 +137,7 @@ func TestTagRedactionInSafeDetails(t *testing.T) {
137137
tt.Run("local", func(tt testutils.T) { theTest(tt, decoratedErr) })
138138

139139
enc := errbase.EncodeError(context.Background(), decoratedErr)
140-
newErr := errbase.DecodeError(context.Background(), enc)
140+
newErr := errbase.DecodeError(context.Background(), &enc)
141141

142142
tt.Run("remote", func(tt testutils.T) { theTest(tt, newErr) })
143143

contexttags/with_context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/cockroachdb/errors/errorspb"
2323
"github.com/cockroachdb/logtags"
2424
"github.com/cockroachdb/redact"
25-
"github.com/gogo/protobuf/proto"
25+
"google.golang.org/protobuf/proto"
2626
)
2727

2828
type withContext struct {
@@ -79,7 +79,7 @@ func encodeWithContext(_ context.Context, err error) (string, []string, proto.Me
7979
w := err.(*withContext)
8080
p := &errorspb.TagsPayload{}
8181
for _, t := range w.tags.Get() {
82-
p.Tags = append(p.Tags, errorspb.TagPayload{Tag: t.Key(), Value: t.ValueStr()})
82+
p.Tags = append(p.Tags, &errorspb.TagPayload{Tag: t.Key(), Value: t.ValueStr()})
8383
}
8484
return "", w.SafeDetails(), p
8585
}

domains/with_domain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
"github.com/cockroachdb/errors/errbase"
2222
"github.com/cockroachdb/redact"
23-
"github.com/gogo/protobuf/proto"
23+
"google.golang.org/protobuf/proto"
2424
)
2525

2626
// withDomain is a wrapper type that adds a domain annotation to an

errbase/adapters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"os"
2222

2323
"github.com/cockroachdb/errors/errorspb"
24-
"github.com/gogo/protobuf/proto"
2524
pkgErr "github.com/pkg/errors"
25+
"google.golang.org/protobuf/proto"
2626
)
2727

2828
// This file provides the library the ability to encode/decode

errbase/adapters_errno.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// implied. See the License for the specific language governing
1313
// permissions and limitations under the License.
1414

15+
//go:build !plan9
1516
// +build !plan9
1617

1718
package errbase
@@ -23,7 +24,7 @@ import (
2324
"syscall"
2425

2526
"github.com/cockroachdb/errors/errorspb"
26-
"github.com/gogo/protobuf/proto"
27+
"google.golang.org/protobuf/proto"
2728
)
2829

2930
const thisArch = runtime.GOOS + ":" + runtime.GOARCH

0 commit comments

Comments
 (0)