Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ftr]: support return exception #30

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/dubbo/java-client/pom.xml
Expand Up @@ -13,7 +13,7 @@
<maven.compiler.target>8</maven.compiler.target>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
<dubbo.version>3.0.0</dubbo.version>
<dubbo.version>3.0.3</dubbo.version>
<junit.version>4.12</junit.version>
<spring-test.version>4.3.16.RELEASE</spring-test.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
Expand Down
2 changes: 1 addition & 1 deletion example/dubbo/java-server/pom.xml
Expand Up @@ -13,7 +13,7 @@
<maven.compiler.target>8</maven.compiler.target>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
<dubbo.version>3.0.0</dubbo.version>
<dubbo.version>3.0.3</dubbo.version>
<junit.version>4.12</junit.version>
<spring-test.version>4.3.16.RELEASE</spring-test.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
Expand Down
20 changes: 11 additions & 9 deletions internal/http2/triple_controller.go
Expand Up @@ -444,18 +444,20 @@ func (hc *TripleController) UnaryInvoke(ctx context.Context, path string, arg, r
}
}

if msg == "" && len(attachment) > 0 {
if attachment[constant.TrailerKeyGrpcDetailsBin] != "" {
trailerKeyGrpcDetailsBin := attachment[constant.TrailerKeyGrpcDetailsBin]
trailerKeyGrpcDetails, _ := base64.RawStdEncoding.DecodeString(trailerKeyGrpcDetailsBin)
if trailerKeyGrpcDetailsBin != "" {
msg = string(trailerKeyGrpcDetails)
if codes.Code(code) != codes.OK {
hc.option.Logger.Errorf("TripleController.UnaryInvoke: triple status not success, msg = %s, code = %d", msg, code)

if len(attachment) > 0 {
if attachment[constant.TrailerKeyGrpcDetailsBin] != "" {
trailerKeyGrpcDetailsBin := attachment[constant.TrailerKeyGrpcDetailsBin]
trailerKeyGrpcDetails, _ := base64.RawStdEncoding.DecodeString(trailerKeyGrpcDetailsBin)
if trailerKeyGrpcDetailsBin != "" {
details := string(trailerKeyGrpcDetails)
return *common.NewErrorWithAttachment(perrors.Errorf("TripleController.UnaryInvoke: triple status not success, msg = %s, code = %d,grpc-status-details-bin = %+v", msg, code, details), attachment)
}
}
}
}

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

Expand Down
14 changes: 14 additions & 0 deletions internal/stream/processor.go
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"errors"
"fmt"
spb "google.golang.org/genproto/googleapis/rpc/status"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move it to the 2rd import block.

"reflect"
"sync"
)
Expand Down Expand Up @@ -68,7 +69,20 @@ func (p *baseProcessor) handleRPCErr(err error) {
if !ok {
err = status.Errorf(codes.Unknown, err.Error())
appStatus, _ = status.FromError(err)

var errInfo = &spb.Status{
Message: fmt.Sprintf("%+v", err),
}
appStatus, err = appStatus.WithDetails(errInfo)

if err != nil {
// If this errored, it will always error
// here, so better panic so we can figure
// out why than have this silently passing.
panic(fmt.Sprintf("Unexpected error attaching metadata: %v", err))
}
}

p.stream.WriteCloseMsgTypeWithStatus(appStatus)
}

Expand Down