-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
61617: lint: forbid gRPC Status.WithDetails() due to gogoproto issues r=tbg a=erikgrinaker gRPC's `Status.WithDetails()` allows callers to attach Protobuf-structured details to gRPC errors. Unfortunately, this does not work with gogoproto types, since they're stored in an `Any` field internally and gogo types are not registered in the standard Protobuf type registry. Calling `Details()` with such a type will return an unmarshalling error in place of the detail. To avoid this problem, this patch adds a linter that disallows any use of `Status.WithDetails()`. Note that there is a separate package `github.com/gogo/status` that emulates the standard gRPC `status` package using gogoproto Protobufs instead. However, due to the uncertain future of the gogoproto project we are hesitant to introduce additional gogo dependencies. Related to #56208 and cockroachdb/errors#63. Release justification: non-production code changes Release note: None Co-authored-by: Erik Grinaker <[email protected]>
- Loading branch information
Showing
8 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...nt/passes/forbiddenmethod/testdata/src/google.golang.org/grpc/internal/status/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "status", | ||
srcs = ["status.go"], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/testutils/lint/passes/forbiddenmethod/testdata/src/google.golang.org/grpc/internal/status", | ||
visibility = ["//visibility:public"], | ||
) |
17 changes: 17 additions & 0 deletions
17
...lint/passes/forbiddenmethod/testdata/src/google.golang.org/grpc/internal/status/status.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package status | ||
|
||
type Status struct{} | ||
|
||
func (s *Status) WithDetails() (*Status, error) { | ||
return s, nil | ||
} |
8 changes: 8 additions & 0 deletions
8
...tutils/lint/passes/forbiddenmethod/testdata/src/google.golang.org/grpc/status/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "status", | ||
srcs = ["status.go"], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/testutils/lint/passes/forbiddenmethod/testdata/src/google.golang.org/grpc/status", | ||
visibility = ["//visibility:public"], | ||
) |
23 changes: 23 additions & 0 deletions
23
...estutils/lint/passes/forbiddenmethod/testdata/src/google.golang.org/grpc/status/status.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package status | ||
|
||
import ( | ||
istatus "google.golang.org/grpc/internal/status" | ||
) | ||
|
||
// This mirrors the gRPC structure, where status.Status is an alias for an | ||
// internal type. The lint needs to check on the internal type. | ||
type Status = istatus.Status | ||
|
||
func New(_ int, _ string) *Status { | ||
return &Status{} | ||
} |
9 changes: 9 additions & 0 deletions
9
pkg/testutils/lint/passes/forbiddenmethod/testdata/src/grpcstatuswithdetailstest/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "grpstatuswithdetailstest", | ||
srcs = ["foo.go"], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/testutils/lint/passes/forbiddenmethod/testdata/src/grpcstatuswithdetailstest", | ||
visibility = ["//visibility:public"], | ||
deps = ["@org_golang_google_grpc//:go_default_library"], | ||
) |
21 changes: 21 additions & 0 deletions
21
pkg/testutils/lint/passes/forbiddenmethod/testdata/src/grpcstatuswithdetailstest/status.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package grpcstatuswithdetailstest | ||
|
||
import "google.golang.org/grpc/status" | ||
|
||
func F() { | ||
s := status.New(1, "message") | ||
_, _ = s.WithDetails() // want `Illegal call to Status.WithDetails\(\)` | ||
|
||
//nolint:grpcstatuswithdetails | ||
_, _ = s.WithDetails() | ||
} |