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

Fix : the consumer cannot get the real cause error from provider #652

Merged
merged 5 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cluster/cluster_impl/failover_cluster_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cluster_impl

import (
"context"
"fmt"
"strconv"
)

Expand Down Expand Up @@ -91,8 +92,10 @@ func (invoker *failoverClusterInvoker) Invoke(ctx context.Context, invocation pr
invokerSvc := invoker.GetUrl().Service()
invokerUrl := invoker.directory.GetUrl()
return &protocol.RPCResult{
Err: perrors.Errorf("Failed to invoke the method %v in the service %v. Tried %v times of the providers %v (%v/%v)from the registry %v on the consumer %v using the dubbo version %v. Last error is %v.",
methodName, invokerSvc, retries, providers, len(providers), len(invokers), invokerUrl, ip, constant.Version, result.Error().Error(),
Err: perrors.Wrap(result.Error(), fmt.Sprintf("Failed to invoke the method %v in the service %v. "+
"Tried %v times of the providers %v (%v/%v)from the registry %v on the consumer %v using the dubbo version %v. "+
"Last error is %+v.", methodName, invokerSvc, retries, providers, len(providers), len(invokers),
invokerUrl, ip, constant.Version, result.Error().Error()),
)}
}

Expand Down
18 changes: 17 additions & 1 deletion common/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import (
"sync"
)

import (
"github.com/apache/dubbo-go-hessian2/java_exception"
perrors "github.com/pkg/errors"
)

import (
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
Expand Down Expand Up @@ -154,7 +159,18 @@ func (p *Proxy) Implement(v common.RPCService) {
}

err = result.Error()
logger.Debugf("[makeDubboCallProxy] result: %v, err: %v", result.Result(), err)
if err != nil {
// the cause reason
err = perrors.Cause(err)
// if some error happened, it should be log some info in the seperate file.
if throwabler, ok := err.(java_exception.Throwabler); ok {
logger.Warnf("invoke service throw exception: %v , stackTraceElements: %v", err.Error(), throwabler.GetStackTrace())
} else {
logger.Warnf("result err: %v", err)
}
} else {
Copy link
Member

Choose a reason for hiding this comment

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

建议else能去则去掉下

logger.Debugf("[makeDubboCallProxy] result: %v, err: %v", result.Result(), err)
}
if len(outs) == 1 {
return []reflect.Value{reflect.ValueOf(&err).Elem()}
}
Expand Down
2 changes: 2 additions & 0 deletions protocol/invocation/rpcinvocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ func (r *RPCInvocation) Invoker() protocol.Invoker {

// nolint
func (r *RPCInvocation) SetInvoker(invoker protocol.Invoker) {
r.lock.Lock()
defer r.lock.Unlock()
r.invoker = invoker
}

Expand Down