Skip to content

Commit

Permalink
fix: triple error
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenceLiZhixin committed Oct 12, 2021
1 parent d4360ee commit 9fe94d0
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 18 deletions.
9 changes: 5 additions & 4 deletions example/dubbo/go-client/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (

import (
"github.com/dubbogo/triple/example/dubbo/proto"
"github.com/dubbogo/triple/pkg/common"
tripleConstant "github.com/dubbogo/triple/pkg/common/constant"
)

Expand All @@ -46,7 +47,7 @@ func init() {
config.SetConsumerService(greeterProvider)
runtime.SetMutexProfileFraction(1)
}
// need to setup environment variable "CONF_CONSUMER_FILE_PATH" to "conf/client.yml" before run
// Set up DUBBO_GO_CONFIG_PATH to dubbogo.yml before run
func main() {
go func() {
_ = http.ListenAndServe("0.0.0.0:6061", nil)
Expand All @@ -55,7 +56,7 @@ func main() {
time.Sleep(time.Second * 3)
testSayHello()

//testSayHelloWithError()
testSayHelloWithError()

// stream is not available for dubbo-java
//testSayHelloStream()
Expand All @@ -65,7 +66,7 @@ func main() {
}

func testSayHelloWithError() {
logger.Infof("testSayHello")
logger.Infof("testSayHelloWithError")

ctx := context.Background()
ctx = context.WithValue(ctx, tripleConstant.TripleCtxKey(tripleConstant.TripleRequestID), "triple-request-id-demo")
Expand All @@ -74,7 +75,7 @@ func testSayHelloWithError() {
Name: "laurence",
}
user, err := greeterProvider.SayHelloWithError(ctx, &req)
logger.Infof("GetResponse error = %+v, rspUser = %+v", err, user)
logger.Infof("GetResponse error = %+v, rspUser = %+v", err.(*common.TripleError).StacksTrace(), user)
}

func testSayHello() {
Expand Down
2 changes: 1 addition & 1 deletion example/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/dubbogo/triple/example
go 1.13

require (
dubbo.apache.org/dubbo-go/v3 v3.0.0-rc2.0.20211007054845-07e6f4405545
dubbo.apache.org/dubbo-go/v3 v3.0.0-rc2.0.20211011045321-e213f97fda57
github.com/dubbogo/triple v1.0.6-0.20210909153707-3620c8d2d97c
github.com/golang/protobuf v1.5.2
github.com/pkg/errors v0.9.1
Expand Down
6 changes: 4 additions & 2 deletions example/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
dubbo.apache.org/dubbo-go/v3 v3.0.0-rc2.0.20211007054845-07e6f4405545 h1:7hwhZ5YPaRexPOyHVTFcYqIsBcB8s/uFdEyKts5yXS4=
dubbo.apache.org/dubbo-go/v3 v3.0.0-rc2.0.20211007054845-07e6f4405545/go.mod h1:84/HH7kK42HDa3DXrtj0Eyy2bVBstV3Z3sF0s4NcXZY=
dubbo.apache.org/dubbo-go/v3 v3.0.0-rc2.0.20211011045321-e213f97fda57 h1:8s534SRhqQ7Kl6SNJKOoS2PtmEWuGz6zpEj9hixvs/A=
dubbo.apache.org/dubbo-go/v3 v3.0.0-rc2.0.20211011045321-e213f97fda57/go.mod h1:84/HH7kK42HDa3DXrtj0Eyy2bVBstV3Z3sF0s4NcXZY=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0=
Expand Down Expand Up @@ -179,9 +181,9 @@ github.com/dubbogo/go-zookeeper v1.0.3 h1:UkuY+rBsxdT7Bs63QAzp9z7XqQ53W1j8E5rwl8
github.com/dubbogo/go-zookeeper v1.0.3/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c=
github.com/dubbogo/gost v1.9.0/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/dubbogo/gost v1.11.12/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI=
github.com/dubbogo/gost v1.11.16/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI=
github.com/dubbogo/gost v1.11.17 h1:Dwaoqv/G21nYsGkeQoLbCAOryRPl6B7pEsZSJcr55nE=
github.com/dubbogo/gost v1.11.17/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI=
github.com/dubbogo/gost v1.11.18-0.20211011142005-8a95129ef6e2 h1:UU3dQZo/NE6VUf6ib5lyAjDfxuI6qX+aq8OZZx649JE=
github.com/dubbogo/gost v1.11.18-0.20211011142005-8a95129ef6e2/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI=
github.com/dubbogo/jsonparser v1.0.1/go.mod h1:tYAtpctvSP/tWw4MeelsowSPgXQRVHHWbqL6ynps8jU=
github.com/dubbogo/net v0.0.4 h1:Rn9aMPZwOiRE22YhtxmDEE3H0Q3cfVRNhuEjNMelJ/8=
github.com/dubbogo/net v0.0.4/go.mod h1:1CGOnM7X3he+qgGNqjeADuE5vKZQx/eMSeUkpU3ujIc=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.15

require (
github.com/apache/dubbo-go-hessian2 v1.9.1
github.com/dubbogo/gost v1.11.16
github.com/dubbogo/gost v1.11.18-0.20211011142005-8a95129ef6e2
github.com/dubbogo/net v0.0.4
github.com/golang/protobuf v1.5.2
github.com/pkg/errors v0.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dubbogo/go-zookeeper v1.0.3/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c=
github.com/dubbogo/gost v1.9.0/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8=
github.com/dubbogo/gost v1.11.16 h1:fvOw8aKQ0BuUYuD+MaXAYFvT7tg2l7WAS5SL5gZJpFs=
github.com/dubbogo/gost v1.11.16/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI=
github.com/dubbogo/gost v1.11.18-0.20211011142005-8a95129ef6e2 h1:UU3dQZo/NE6VUf6ib5lyAjDfxuI6qX+aq8OZZx649JE=
github.com/dubbogo/gost v1.11.18-0.20211011142005-8a95129ef6e2/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI=
github.com/dubbogo/jsonparser v1.0.1/go.mod h1:tYAtpctvSP/tWw4MeelsowSPgXQRVHHWbqL6ynps8jU=
github.com/dubbogo/net v0.0.4 h1:Rn9aMPZwOiRE22YhtxmDEE3H0Q3cfVRNhuEjNMelJ/8=
github.com/dubbogo/net v0.0.4/go.mod h1:1CGOnM7X3he+qgGNqjeADuE5vKZQx/eMSeUkpU3ujIc=
Expand Down
15 changes: 7 additions & 8 deletions internal/http2/triple_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ func (hc *TripleController) UnaryInvoke(ctx context.Context, path string, arg, r
}

if codes.Code(code) != codes.OK {
hc.option.Logger.Errorf("TripleController.UnaryInvoke: triple status not success, msg = %s, code = %d", msg, code)

hc.option.Logger.Warnf("TripleController.UnaryInvoke: triple status not success, msg = %s, code = %d", msg, code)
var stackTracesStr string
if len(attachment) > 0 {
if attachment[constant.TrailerKeyGrpcDetailsBin] != "" {
trailerKeyGrpcDetailsBin := attachment[constant.TrailerKeyGrpcDetailsBin]
Expand All @@ -454,21 +454,20 @@ func (hc *TripleController) UnaryInvoke(ctx context.Context, path string, arg, r
details, _ := status.NewStatus(codes.Internal, "").WithDetails(&errdetails.DebugInfo{})
detailProto := details.Proto()
if err := proto.Unmarshal(trailerKeyGrpcDetails, detailProto); err == nil && len(detailProto.Details) > 0 {
stackTracesStr := strings.Replace(detailProto.Details[0].String(), `\n`, "\n", -1)
stackTracesStr = strings.Replace(detailProto.Details[0].String(), `\n`, "\n", -1)
stackTracesStr = strings.Replace(stackTracesStr, `\t`, "\t", -1)
return *common.NewErrorWithAttachment(perrors.Errorf("TripleController.UnaryInvoke: triple status not success, msg = %s,\n code = %d,\n error from server stacks are %s\n", msg, code, stackTracesStr), attachment)
}
return *common.NewErrorWithAttachment(perrors.Errorf("TripleController.UnaryInvoke: triple status not success, msg = %s, code = %d, error stacks not found", msg, code), attachment)
}
}
}

return *common.NewErrorWithAttachment(perrors.Errorf("TripleController.UnaryInvoke: triple status not success, msg = %s, code = %d", msg, code), attachment)
// Now only error returned by server side rpc function can user level error get attachment of triple
// that is because error is nil when rpc success, and user can't get attachment.
return *common.NewErrorWithAttachment(common.NewTripleError(msg, code, stackTracesStr, attachment), attachment)
}

// all split data are collected and to unmarshal
if err := hc.twoWayCodec.UnmarshalResponse(rspData, reply); err != nil {
hc.option.Logger.Errorf("client unmarshal rsp err= %v\n", err)
hc.option.Logger.Errorf("client unmarshal rsp err = %v\n", err)
return *common.NewErrorWithAttachment(err, attachment)
}
return *common.NewErrorWithAttachment(nil, attachment)
Expand Down
33 changes: 33 additions & 0 deletions pkg/common/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package common

type TripleError struct {
msg string
stacksTrace string
attachment map[string]string
code int
}

func NewTripleError(msg string, code int, stacksTrace string, attachment map[string]string) *TripleError {
return &TripleError{
msg: msg,
code: code,
attachment: attachment,
stacksTrace: stacksTrace,
}
}

func (e *TripleError) Error() string {
return e.msg
}

func (e *TripleError) StacksTrace() string {
return e.stacksTrace
}

func (e *TripleError) Attachment() map[string]string {
return e.attachment
}

func (e *TripleError) Code() int {
return e.code
}

0 comments on commit 9fe94d0

Please sign in to comment.