Skip to content

Commit

Permalink
fix: grpc WithDetails if not proto.Message
Browse files Browse the repository at this point in the history
This makes tests work with prutal
  • Loading branch information
xiaost committed Feb 27, 2025
1 parent fc268fa commit 26fb8f1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [pull_request]

jobs:
run-tests:
runs-on: [ self-hosted, X64 ]
runs-on: [ self-hosted, Linux, X64 ]
steps:
- uses: actions/checkout@v4
- name: Set up Go
Expand Down
8 changes: 6 additions & 2 deletions pbrpc/failedcall/error_handler/errhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/cloudwego/kitex/pkg/transmeta"
"github.com/cloudwego/kitex/server"
"github.com/cloudwego/kitex/transport"
"google.golang.org/protobuf/proto"
)

var testaddr string
Expand Down Expand Up @@ -184,8 +185,11 @@ func TestHandlerReturnBizError(t *testing.T) {
test.Assert(t, bizerror.BizStatusCode() == 404)
test.Assert(t, bizerror.BizMessage() == "not found")
test.Assert(t, reflect.DeepEqual(bizerror.BizExtra(), map[string]string{"version": "v1.0.0"}))
str := bizerror.(status.Iface).GRPCStatus().Details()[0].(*stability.STRequest).Str
test.Assert(t, reflect.DeepEqual(str, "hello world"))
// only works for proto.Message
if _, ok := any((*stability.STRequest)(nil)).(proto.Message); ok {
str := bizerror.(status.Iface).GRPCStatus().Details()[0].(*stability.STRequest).Str
test.Assert(t, reflect.DeepEqual(str, "hello world"))
}
}

func TestHandlerPanic(t *testing.T) {
Expand Down
9 changes: 7 additions & 2 deletions pbrpc/failedcall/error_handler/mockfailed_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/cloudwego/kitex/pkg/kerrors"
"github.com/cloudwego/kitex/pkg/remote"
"github.com/cloudwego/kitex/pkg/remote/trans/nphttp2/status"
"google.golang.org/protobuf/proto"
)

var (
Expand Down Expand Up @@ -54,8 +55,12 @@ func (*STServiceHandler) TestSTReq(ctx context.Context, req *stability.STRequest
case "bizErrWithDetail":
bizStatusErr := kerrors.NewGRPCBizStatusErrorWithExtra(404, "not found", map[string]string{"version": "v1.0.0"})
if sterr, ok := bizStatusErr.(kerrors.GRPCStatusIface); ok {
st, _ := sterr.GRPCStatus().WithDetails(&stability.STRequest{Str: "hello world"})
sterr.SetGRPCStatus(st)
details := &stability.STRequest{Str: "hello world"} // WithDetails only works with proto.Message
v := any(details)
if m, ok := v.(proto.Message); ok {
st, _ := sterr.GRPCStatus().WithDetails(m)
sterr.SetGRPCStatus(st)
}
}
return nil, bizStatusErr
case panicStr:
Expand Down
4 changes: 3 additions & 1 deletion thrift_streaming/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,7 @@ fi

cd exitserver
echo -e "\nbuilding exitserver @ $PWD\nPlease run ./update_go_mod.sh if any Go compatibility issue\n"
go build
# TODO: remove checklinkname if no longer needed.
# we can not ugprade dymanicgo now, it may not work with the legacy kitex version

Check warning on line 154 in thrift_streaming/generate.sh

View workflow job for this annotation

GitHub Actions / compliant-checks

"ugprade" should be "upgrade".
go build -ldflags=-checklinkname=0
mv exitserver $ROOT/binaries

0 comments on commit 26fb8f1

Please sign in to comment.