diff --git a/cluster/cluster_impl/base_cluster_invoker.go b/cluster/cluster_impl/base_cluster_invoker.go index 38c210bbb5bb6e0de0ca09ca46405bbd3f9cf7ab..3b0c587cce9eba4825fdb566c3c790c41c805c09 100644 --- a/cluster/cluster_impl/base_cluster_invoker.go +++ b/cluster/cluster_impl/base_cluster_invoker.go @@ -15,7 +15,7 @@ package cluster_impl import ( - "github.com/pkg/errors" + perrors "github.com/pkg/errors" "go.uber.org/atomic" ) @@ -60,7 +60,7 @@ func (invoker *baseClusterInvoker) IsAvailable() bool { func (invoker *baseClusterInvoker) checkInvokers(invokers []protocol.Invoker, invocation protocol.Invocation) error { if len(invokers) == 0 { ip, _ := utils.GetLocalIP() - return errors.Errorf("Failed to invoke the method %v. No provider available for the service %v from "+ + return perrors.Errorf("Failed to invoke the method %v. No provider available for the service %v from "+ "registry %v on the consumer %v using the dubbo version %v .Please check if the providers have been started and registered.", invocation.MethodName(), invoker.directory.GetUrl().SubURL.Key(), invoker.directory.GetUrl().String(), ip, version.Version) } @@ -72,7 +72,7 @@ func (invoker *baseClusterInvoker) checkInvokers(invokers []protocol.Invoker, in func (invoker *baseClusterInvoker) checkWhetherDestroyed() error { if invoker.destroyed.Load() { ip, _ := utils.GetLocalIP() - return errors.Errorf("Rpc cluster invoker for %v on consumer %v use dubbo version %v is now destroyed! can not invoke any more. ", + return perrors.Errorf("Rpc cluster invoker for %v on consumer %v use dubbo version %v is now destroyed! can not invoke any more. ", invoker.directory.GetUrl().Service(), ip, version.Version) } return nil diff --git a/cluster/cluster_impl/failover_cluster_invoker.go b/cluster/cluster_impl/failover_cluster_invoker.go index 8642b63b360c2867e9b4e20ac85bc738303b89d3..d81986d02f4743a1f26b8b5597df089d369c174f 100644 --- a/cluster/cluster_impl/failover_cluster_invoker.go +++ b/cluster/cluster_impl/failover_cluster_invoker.go @@ -15,7 +15,7 @@ package cluster_impl import ( - "github.com/pkg/errors" + perrors "github.com/pkg/errors" ) import ( @@ -93,7 +93,7 @@ func (invoker *failoverClusterInvoker) Invoke(invocation protocol.Invocation) pr } } ip, _ := utils.GetLocalIP() - return &protocol.RPCResult{Err: errors.Errorf("Failed to invoke the method %v in the service %v . Tried %v times of "+ + 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, invoker.GetUrl().Service(), retries, providers, len(providers), len(invokers), invoker.directory.GetUrl(), ip, version.Version, result.Error().Error(), )} diff --git a/cluster/cluster_impl/failover_cluster_test.go b/cluster/cluster_impl/failover_cluster_test.go index 6744e821028415049ec4095e94b814163c88b2ac..b7009be20effc8b96e9d914dc5b63ce83836493d 100644 --- a/cluster/cluster_impl/failover_cluster_test.go +++ b/cluster/cluster_impl/failover_cluster_test.go @@ -22,7 +22,7 @@ import ( ) import ( log "github.com/AlexStocks/log4go" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" "github.com/stretchr/testify/assert" ) @@ -81,7 +81,7 @@ func (bi *MockInvoker) Invoke(invocation protocol.Invocation) protocol.Result { if count >= bi.successCount { success = true } else { - err = errors.New("error") + err = perrors.New("error") } result := &protocol.RPCResult{Err: err, Rest: rest{tried: count, success: success}} diff --git a/common/proxy/proxy_test.go b/common/proxy/proxy_test.go index ec3df722703f16a957a1a6eec90eb19f326937dd..6a12af8a70552ec5348d75f9c57bec31670806ad 100644 --- a/common/proxy/proxy_test.go +++ b/common/proxy/proxy_test.go @@ -21,7 +21,7 @@ import ( ) import ( - "github.com/pkg/errors" + perrors "github.com/pkg/errors" "github.com/stretchr/testify/assert" ) @@ -81,7 +81,7 @@ func TestProxy_Implement(t *testing.T) { methodOne func(context.Context, interface{}, *struct{}) error } s1 := &S1{TestService: *s, methodOne: func(i context.Context, i2 interface{}, i3 *struct{}) error { - return errors.New("errors") + return perrors.New("errors") }} p.Implement(s1) err = s1.MethodOne(nil, 0, false, nil) diff --git a/common/rpc_service.go b/common/rpc_service.go index 4c71fec46a1dd0aee664f95b6a03729c4e1f8efd..82745527672f24c3da10c1d1a4c513c0c112a0c9 100644 --- a/common/rpc_service.go +++ b/common/rpc_service.go @@ -25,7 +25,7 @@ import ( import ( log "github.com/AlexStocks/log4go" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" ) // rpc service interface @@ -129,17 +129,17 @@ func (sm *serviceMap) Register(protocol string, rcvr RPCService) (string, error) if sname == "" { s := "no service name for type " + s.rcvrType.String() log.Error(s) - return "", errors.New(s) + return "", perrors.New(s) } if !isExported(sname) { s := "type " + sname + " is not exported" log.Error(s) - return "", errors.New(s) + return "", perrors.New(s) } sname = rcvr.Service() if server := sm.GetService(protocol, sname); server != nil { - return "", errors.New("service already defined: " + sname) + return "", perrors.New("service already defined: " + sname) } s.name = sname s.methods = make(map[string]*MethodType) @@ -151,7 +151,7 @@ func (sm *serviceMap) Register(protocol string, rcvr RPCService) (string, error) if len(s.methods) == 0 { s := "type " + sname + " has no exported methods of suitable type" log.Error(s) - return "", errors.New(s) + return "", perrors.New(s) } sm.mutex.Lock() sm.serviceMap[protocol][s.name] = s @@ -162,18 +162,18 @@ func (sm *serviceMap) Register(protocol string, rcvr RPCService) (string, error) func (sm *serviceMap) UnRegister(protocol, serviceName string) error { if protocol == "" || serviceName == "" { - return errors.New("protocol or serviceName is nil") + return perrors.New("protocol or serviceName is nil") } sm.mutex.RLock() svcs, ok := sm.serviceMap[protocol] if !ok { sm.mutex.RUnlock() - return errors.New("no services for " + protocol) + return perrors.New("no services for " + protocol) } _, ok = svcs[serviceName] if !ok { sm.mutex.RUnlock() - return errors.New("no service for " + serviceName) + return perrors.New("no service for " + serviceName) } sm.mutex.RUnlock() diff --git a/common/url.go b/common/url.go index 960bf3dd53411bae0b03e4229107b2f11a169a74..66dfaed6c1f0b2dfc2cd626ca3030f38528a8704 100644 --- a/common/url.go +++ b/common/url.go @@ -24,7 +24,7 @@ import ( ) import ( - "github.com/pkg/errors" + perrors "github.com/pkg/errors" ) import ( @@ -157,18 +157,18 @@ func NewURL(ctx context.Context, urlString string, opts ...option) (URL, error) rawUrlString, err = url.QueryUnescape(urlString) if err != nil { - return s, errors.Errorf("url.QueryUnescape(%s), error{%v}", urlString, err) + return s, perrors.Errorf("url.QueryUnescape(%s), error{%v}", urlString, err) } //rawUrlString = "//" + rawUrlString serviceUrl, err = url.Parse(rawUrlString) if err != nil { - return s, errors.Errorf("url.Parse(url string{%s}), error{%v}", rawUrlString, err) + return s, perrors.Errorf("url.Parse(url string{%s}), error{%v}", rawUrlString, err) } s.Params, err = url.ParseQuery(serviceUrl.RawQuery) if err != nil { - return s, errors.Errorf("url.ParseQuery(raw url string{%s}), error{%v}", serviceUrl.RawQuery, err) + return s, perrors.Errorf("url.ParseQuery(raw url string{%s}), error{%v}", serviceUrl.RawQuery, err) } s.PrimitiveURL = urlString @@ -180,7 +180,7 @@ func NewURL(ctx context.Context, urlString string, opts ...option) (URL, error) if strings.Contains(s.Location, ":") { s.Ip, s.Port, err = net.SplitHostPort(s.Location) if err != nil { - return s, errors.Errorf("net.SplitHostPort(Url.Host{%s}), error{%v}", s.Location, err) + return s, perrors.Errorf("net.SplitHostPort(Url.Host{%s}), error{%v}", s.Location, err) } } // diff --git a/common/utils/net.go b/common/utils/net.go index b157c223a3ae2d142d811c914630eb704e4fc6fe..b9f1786e2bfea4337d28c0d963940558f6c3ecc2 100644 --- a/common/utils/net.go +++ b/common/utils/net.go @@ -19,7 +19,7 @@ import ( ) import ( - "github.com/pkg/errors" + perrors "github.com/pkg/errors" ) var ( @@ -38,14 +38,14 @@ func init() { func GetLocalIP() (string, error) { ifs, err := net.Interfaces() if err != nil { - return "", errors.WithStack(err) + return "", perrors.WithStack(err) } var ipAddr []byte for _, i := range ifs { addrs, err := i.Addrs() if err != nil { - return "", errors.WithStack(err) + return "", perrors.WithStack(err) } var ip net.IP for _, addr := range addrs { @@ -64,7 +64,7 @@ func GetLocalIP() (string, error) { } if ipAddr == nil { - return "", errors.Errorf("can not get local IP") + return "", perrors.Errorf("can not get local IP") } return net.IP(ipAddr).String(), nil diff --git a/config/config_loader.go b/config/config_loader.go index dd1c60d632390838f8c0e34af377e4f6d9800327..ff164ac9ed210fc671bc4637bbaefb071e91f7fd 100644 --- a/config/config_loader.go +++ b/config/config_loader.go @@ -25,7 +25,7 @@ import ( import ( log "github.com/AlexStocks/log4go" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" "gopkg.in/yaml.v2" ) @@ -73,10 +73,10 @@ func logInit() error { confFile = os.Getenv(constant.APP_LOG_CONF_FILE) if confFile == "" { - return errors.Errorf("log configure file name is nil") + return perrors.Errorf("log configure file name is nil") } if path.Ext(confFile) != ".xml" { - return errors.Errorf("log configure file name{%v} suffix must be .xml", confFile) + return perrors.Errorf("log configure file name{%v} suffix must be .xml", confFile) } log.LoadConfiguration(confFile) @@ -86,28 +86,28 @@ func logInit() error { func consumerInit(confConFile string) error { if confConFile == "" { - return errors.Errorf("application configure(consumer) file name is nil") + return perrors.Errorf("application configure(consumer) file name is nil") } if path.Ext(confConFile) != ".yml" { - return errors.Errorf("application configure file name{%v} suffix must be .yml", confConFile) + return perrors.Errorf("application configure file name{%v} suffix must be .yml", confConFile) } confFileStream, err := ioutil.ReadFile(confConFile) if err != nil { - return errors.Errorf("ioutil.ReadFile(file:%s) = error:%v", confConFile, errors.Cause(err)) + return perrors.Errorf("ioutil.ReadFile(file:%s) = error:%v", confConFile, perrors.WithStack(err)) } consumerConfig = &ConsumerConfig{} err = yaml.Unmarshal(confFileStream, consumerConfig) if err != nil { - return errors.Errorf("yaml.Unmarshal() = error:%v", errors.Cause(err)) + return perrors.Errorf("yaml.Unmarshal() = error:%v", perrors.WithStack(err)) } if consumerConfig.RequestTimeout, err = time.ParseDuration(consumerConfig.Request_Timeout); err != nil { - return errors.WithMessagef(err, "time.ParseDuration(Request_Timeout{%#v})", consumerConfig.Request_Timeout) + return perrors.WithMessagef(err, "time.ParseDuration(Request_Timeout{%#v})", consumerConfig.Request_Timeout) } if consumerConfig.ConnectTimeout, err = time.ParseDuration(consumerConfig.Connect_Timeout); err != nil { - return errors.WithMessagef(err, "time.ParseDuration(Connect_Timeout{%#v})", consumerConfig.Connect_Timeout) + return perrors.WithMessagef(err, "time.ParseDuration(Connect_Timeout{%#v})", consumerConfig.Connect_Timeout) } log.Debug("consumer config{%#v}\n", consumerConfig) @@ -116,21 +116,21 @@ func consumerInit(confConFile string) error { func providerInit(confProFile string) error { if confProFile == "" { - return errors.Errorf("application configure(provider) file name is nil") + return perrors.Errorf("application configure(provider) file name is nil") } if path.Ext(confProFile) != ".yml" { - return errors.Errorf("application configure file name{%v} suffix must be .yml", confProFile) + return perrors.Errorf("application configure file name{%v} suffix must be .yml", confProFile) } confFileStream, err := ioutil.ReadFile(confProFile) if err != nil { - return errors.Errorf("ioutil.ReadFile(file:%s) = error:%v", confProFile, errors.Cause(err)) + return perrors.Errorf("ioutil.ReadFile(file:%s) = error:%v", confProFile, perrors.WithStack(err)) } providerConfig = &ProviderConfig{} err = yaml.Unmarshal(confFileStream, providerConfig) if err != nil { - return errors.Errorf("yaml.Unmarshal() = error:%v", errors.Cause(err)) + return perrors.Errorf("yaml.Unmarshal() = error:%v", perrors.WithStack(err)) } log.Debug("provider config{%#v}\n", providerConfig) diff --git a/config/service_config.go b/config/service_config.go index 46584b7c28ce177385624f2e903bb6e21ce93de3..0dcb1cecc7bbf5f8b93be39f38e66e8516ccfa3c 100644 --- a/config/service_config.go +++ b/config/service_config.go @@ -24,7 +24,7 @@ import ( ) import ( log "github.com/AlexStocks/log4go" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" "go.uber.org/atomic" ) import ( @@ -73,7 +73,7 @@ func (srvconfig *ServiceConfig) Export() error { //TODO:delay export if srvconfig.unexported != nil && srvconfig.unexported.Load() { - err := errors.Errorf("The service %v has already unexported! ", srvconfig.InterfaceName) + err := perrors.Errorf("The service %v has already unexported! ", srvconfig.InterfaceName) log.Error(err.Error()) return err } @@ -89,7 +89,7 @@ func (srvconfig *ServiceConfig) Export() error { //registry the service reflect methods, err := common.ServiceMap.Register(proto.Name, srvconfig.rpcService) if err != nil { - err := errors.Errorf("The service %v export the protocol %v error! Error message is %v .", srvconfig.InterfaceName, proto.Name, err.Error()) + err := perrors.Errorf("The service %v export the protocol %v error! Error message is %v .", srvconfig.InterfaceName, proto.Name, err.Error()) log.Error(err.Error()) return err } @@ -117,7 +117,7 @@ func (srvconfig *ServiceConfig) Export() error { invoker := extension.GetProxyFactory(providerConfig.ProxyFactory).GetInvoker(*regUrl) exporter := srvconfig.cacheProtocol.Export(invoker) if exporter == nil { - panic(errors.New("New exporter error")) + panic(perrors.New("New exporter error")) } srvconfig.exporters = append(srvconfig.exporters, exporter) } diff --git a/examples/dubbo/go-client/app/client.go b/examples/dubbo/go-client/app/client.go index 9e1ff392b9a3874c7705c629097158a9332c9d9f..89c35a6c69866965007711ac4ecc8b4165d18382 100644 --- a/examples/dubbo/go-client/app/client.go +++ b/examples/dubbo/go-client/app/client.go @@ -32,6 +32,7 @@ import ( ) import ( + _ "github.com/dubbo/go-for-apache-dubbo/common/proxy/proxy_factory" "github.com/dubbo/go-for-apache-dubbo/common/utils" "github.com/dubbo/go-for-apache-dubbo/config" _ "github.com/dubbo/go-for-apache-dubbo/protocol/dubbo" @@ -69,7 +70,7 @@ func main() { if err != nil { panic(err) } - println("res: %s\n", res) + println("res: %v\n", res) time.Sleep(3e9) diff --git a/examples/dubbo/go-client/app/user.go b/examples/dubbo/go-client/app/user.go index bebf93de6c6766103b45cbc8743c511eaa890df8..c6dfc9ebdf1d32db0fe514a6a40086317b82ae92 100644 --- a/examples/dubbo/go-client/app/user.go +++ b/examples/dubbo/go-client/app/user.go @@ -22,10 +22,13 @@ import ( ) import ( - "github.com/dubbo/go-for-apache-dubbo/config" "github.com/dubbogo/hessian2" ) +import ( + "github.com/dubbo/go-for-apache-dubbo/config" +) + type Gender hessian.JavaEnum func init() { diff --git a/examples/dubbo/go-server/app/server.go b/examples/dubbo/go-server/app/server.go index 02f54ca04c91ce2f7e8024c453cb5f92ea1499fe..ed30da6da04e14b6c795a5bfc55a9707ff27002a 100644 --- a/examples/dubbo/go-server/app/server.go +++ b/examples/dubbo/go-server/app/server.go @@ -36,6 +36,7 @@ import ( _ "github.com/dubbo/go-for-apache-dubbo/protocol/dubbo" _ "github.com/dubbo/go-for-apache-dubbo/registry/protocol" + _ "github.com/dubbo/go-for-apache-dubbo/common/proxy/proxy_factory" _ "github.com/dubbo/go-for-apache-dubbo/filter/impl" _ "github.com/dubbo/go-for-apache-dubbo/cluster/cluster_impl" diff --git a/examples/dubbo/go-server/app/user.go b/examples/dubbo/go-server/app/user.go index 40b867b70bdaa0369afd80cef3294af1d8ba407c..1e31338e3ddafe53b3228dd98cdd0d9167def36f 100644 --- a/examples/dubbo/go-server/app/user.go +++ b/examples/dubbo/go-server/app/user.go @@ -22,10 +22,13 @@ import ( ) import ( - "github.com/dubbo/go-for-apache-dubbo/config" "github.com/dubbogo/hessian2" ) +import ( + "github.com/dubbo/go-for-apache-dubbo/config" +) + type Gender hessian.JavaEnum func init() { diff --git a/examples/jsonrpc/go-client/app/client.go b/examples/jsonrpc/go-client/app/client.go index 40bea987b3573834f03b972a05fc828f26d3df05..304165ca96958bf149ba42155874db8b89d31346 100644 --- a/examples/jsonrpc/go-client/app/client.go +++ b/examples/jsonrpc/go-client/app/client.go @@ -31,6 +31,7 @@ import ( ) import ( + _ "github.com/dubbo/go-for-apache-dubbo/common/proxy/proxy_factory" "github.com/dubbo/go-for-apache-dubbo/common/utils" "github.com/dubbo/go-for-apache-dubbo/config" _ "github.com/dubbo/go-for-apache-dubbo/protocol/jsonrpc" @@ -64,7 +65,7 @@ func main() { if err != nil { println("echo - error: %v", err) } else { - println("res: %s", res) + println("res: %v", res) } time.Sleep(3e9) diff --git a/examples/jsonrpc/go-server/app/server.go b/examples/jsonrpc/go-server/app/server.go index f905d26eeb99134812fe772312ab16a8a0511036..a374b1b5c69d68876df9cbb5b2552dbe85f11e0d 100644 --- a/examples/jsonrpc/go-server/app/server.go +++ b/examples/jsonrpc/go-server/app/server.go @@ -30,6 +30,7 @@ import ( ) import ( + _ "github.com/dubbo/go-for-apache-dubbo/common/proxy/proxy_factory" "github.com/dubbo/go-for-apache-dubbo/common/utils" "github.com/dubbo/go-for-apache-dubbo/config" _ "github.com/dubbo/go-for-apache-dubbo/protocol/jsonrpc" diff --git a/protocol/dubbo/client.go b/protocol/dubbo/client.go index 8791882ab28c65c3672ed0703aaaa46c2ac35a67..f191a1275f643d8f1d4917efc1ba2bc18b365096 100644 --- a/protocol/dubbo/client.go +++ b/protocol/dubbo/client.go @@ -24,7 +24,7 @@ import ( "github.com/AlexStocks/getty" log "github.com/AlexStocks/log4go" "github.com/dubbogo/hessian2" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" "go.uber.org/atomic" "gopkg.in/yaml.v2" ) @@ -36,11 +36,11 @@ import ( ) var ( - errInvalidCodecType = errors.New("illegal CodecType") - errInvalidAddress = errors.New("remote address invalid or empty") - errSessionNotExist = errors.New("session not exist") - errClientClosed = errors.New("client closed") - errClientReadTimeout = errors.New("client read timeout") + errInvalidCodecType = perrors.New("illegal CodecType") + errInvalidAddress = perrors.New("remote address invalid or empty") + errSessionNotExist = perrors.New("session not exist") + errClientClosed = perrors.New("client closed") + errClientReadTimeout = perrors.New("client read timeout") clientConf *ClientConfig ) @@ -168,7 +168,7 @@ func (c *Client) CallOneway(addr string, svcUrl common.URL, method string, args o(&copts) } - return errors.WithStack(c.call(CT_OneWay, addr, svcUrl, method, args, nil, nil, copts)) + return perrors.WithStack(c.call(CT_OneWay, addr, svcUrl, method, args, nil, nil, copts)) } // if @reply is nil, the transport layer will get the response without notify the invoker. @@ -184,7 +184,7 @@ func (c *Client) Call(addr string, svcUrl common.URL, method string, args, reply ct = CT_OneWay } - return errors.WithStack(c.call(ct, addr, svcUrl, method, args, reply, nil, copts)) + return perrors.WithStack(c.call(ct, addr, svcUrl, method, args, reply, nil, copts)) } func (c *Client) AsyncCall(addr string, svcUrl common.URL, method string, args interface{}, @@ -195,7 +195,7 @@ func (c *Client) AsyncCall(addr string, svcUrl common.URL, method string, args i o(&copts) } - return errors.WithStack(c.call(CT_TwoWay, addr, svcUrl, method, args, reply, callback, copts)) + return perrors.WithStack(c.call(CT_TwoWay, addr, svcUrl, method, args, reply, callback, copts)) } func (c *Client) call(ct CallType, addr string, svcUrl common.URL, method string, @@ -246,7 +246,7 @@ func (c *Client) call(ct CallType, addr string, svcUrl common.URL, method string defer c.pool.release(conn, err) if err = c.transfer(session, p, rsp, opts); err != nil { - return errors.WithStack(err) + return perrors.WithStack(err) } if ct == CT_OneWay || callback != nil { @@ -261,7 +261,7 @@ func (c *Client) call(ct CallType, addr string, svcUrl common.URL, method string err = rsp.err } - return errors.WithStack(err) + return perrors.WithStack(err) } func (c *Client) Close() { @@ -274,7 +274,7 @@ func (c *Client) Close() { func (c *Client) selectSession(addr string) (*gettyRPCClient, getty.Session, error) { rpcClient, err := c.pool.getGettyRpcClient(DUBBO, addr) if err != nil { - return nil, nil, errors.WithStack(err) + return nil, nil, perrors.WithStack(err) } return rpcClient, rpcClient.selectSession(), nil } @@ -316,7 +316,7 @@ func (c *Client) transfer(session getty.Session, pkg *DubboPackage, rsp.readStart = time.Now() } - return errors.WithStack(err) + return perrors.WithStack(err) } func (c *Client) addPendingResponse(pr *PendingResponse) { diff --git a/protocol/dubbo/client_test.go b/protocol/dubbo/client_test.go index b0adcfcdc3eedde078726a5c6996d38485e7d655..5631d9747a61e0af469f9480eb0a443a9bc4e438 100644 --- a/protocol/dubbo/client_test.go +++ b/protocol/dubbo/client_test.go @@ -23,7 +23,7 @@ import ( import ( "github.com/dubbogo/hessian2" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" "github.com/stretchr/testify/assert" ) @@ -190,7 +190,7 @@ func (u *UserProvider) GetUser0(req []interface{}, rsp *User) error { } func (u *UserProvider) GetUser1(ctx context.Context, req []interface{}, rsp *User) error { - return errors.New("error") + return perrors.New("error") } func (u *UserProvider) Service() string { diff --git a/protocol/dubbo/codec.go b/protocol/dubbo/codec.go index b5f12535069d3d73096786d159643cb4246b749d..ba4d01ab0fbe49745cfd23646596cebaa2ae619e 100644 --- a/protocol/dubbo/codec.go +++ b/protocol/dubbo/codec.go @@ -23,7 +23,7 @@ import ( import ( "github.com/dubbogo/hessian2" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" ) // serial ID @@ -64,7 +64,7 @@ func (p *DubboPackage) Marshal() (*bytes.Buffer, error) { pkg, err := codec.Write(p.Service, p.Header, p.Body) if err != nil { - return nil, errors.WithStack(err) + return nil, perrors.WithStack(err) } return bytes.NewBuffer(pkg), nil @@ -76,7 +76,7 @@ func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, opts ...interface{}) error { // read header err := codec.ReadHeader(&p.Header) if err != nil { - return errors.WithStack(err) + return perrors.WithStack(err) } if len(opts) != 0 { // for client @@ -84,11 +84,11 @@ func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, opts ...interface{}) error { r := client.pendingResponses[SequenceType(p.Header.ID)] if r == nil { - return errors.Errorf("pendingResponses[%v] = nil", p.Header.ID) + return perrors.Errorf("pendingResponses[%v] = nil", p.Header.ID) } p.Body = client.pendingResponses[SequenceType(p.Header.ID)].reply } else { - return errors.Errorf("opts[0] is not *Client") + return perrors.Errorf("opts[0] is not *Client") } } @@ -98,7 +98,7 @@ func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, opts ...interface{}) error { // read body err = codec.ReadBody(p.Body) - return errors.WithStack(err) + return perrors.WithStack(err) } //////////////////////////////////////////// diff --git a/protocol/dubbo/config.go b/protocol/dubbo/config.go index 61e79e5f1851576bcfa772254f2a9f82fcec9427..fa47118db82f5418d4d5f6703e212d82efebe83a 100644 --- a/protocol/dubbo/config.go +++ b/protocol/dubbo/config.go @@ -19,7 +19,7 @@ import ( ) import ( - "github.com/pkg/errors" + perrors "github.com/pkg/errors" ) type ( @@ -101,19 +101,19 @@ func (c *GettySessionParam) CheckValidity() error { var err error if c.keepAlivePeriod, err = time.ParseDuration(c.KeepAlivePeriod); err != nil { - return errors.WithMessagef(err, "time.ParseDuration(KeepAlivePeriod{%#v})", c.KeepAlivePeriod) + return perrors.WithMessagef(err, "time.ParseDuration(KeepAlivePeriod{%#v})", c.KeepAlivePeriod) } if c.tcpReadTimeout, err = time.ParseDuration(c.TcpReadTimeout); err != nil { - return errors.WithMessagef(err, "time.ParseDuration(TcpReadTimeout{%#v})", c.TcpReadTimeout) + return perrors.WithMessagef(err, "time.ParseDuration(TcpReadTimeout{%#v})", c.TcpReadTimeout) } if c.tcpWriteTimeout, err = time.ParseDuration(c.TcpWriteTimeout); err != nil { - return errors.WithMessagef(err, "time.ParseDuration(TcpWriteTimeout{%#v})", c.TcpWriteTimeout) + return perrors.WithMessagef(err, "time.ParseDuration(TcpWriteTimeout{%#v})", c.TcpWriteTimeout) } if c.waitTimeout, err = time.ParseDuration(c.WaitTimeout); err != nil { - return errors.WithMessagef(err, "time.ParseDuration(WaitTimeout{%#v})", c.WaitTimeout) + return perrors.WithMessagef(err, "time.ParseDuration(WaitTimeout{%#v})", c.WaitTimeout) } return nil @@ -123,30 +123,30 @@ func (c *ClientConfig) CheckValidity() error { var err error if c.heartbeatPeriod, err = time.ParseDuration(c.HeartbeatPeriod); err != nil { - return errors.WithMessagef(err, "time.ParseDuration(HeartbeatPeroid{%#v})", c.HeartbeatPeriod) + return perrors.WithMessagef(err, "time.ParseDuration(HeartbeatPeroid{%#v})", c.HeartbeatPeriod) } if c.sessionTimeout, err = time.ParseDuration(c.SessionTimeout); err != nil { - return errors.WithMessagef(err, "time.ParseDuration(SessionTimeout{%#v})", c.SessionTimeout) + return perrors.WithMessagef(err, "time.ParseDuration(SessionTimeout{%#v})", c.SessionTimeout) } if c.failFastTimeout, err = time.ParseDuration(c.FailFastTimeout); err != nil { - return errors.WithMessagef(err, "time.ParseDuration(FailFastTimeout{%#v})", c.FailFastTimeout) + return perrors.WithMessagef(err, "time.ParseDuration(FailFastTimeout{%#v})", c.FailFastTimeout) } - return errors.WithStack(c.GettySessionParam.CheckValidity()) + return perrors.WithStack(c.GettySessionParam.CheckValidity()) } func (c *ServerConfig) CheckValidity() error { var err error if c.sessionTimeout, err = time.ParseDuration(c.SessionTimeout); err != nil { - return errors.WithMessagef(err, "time.ParseDuration(SessionTimeout{%#v})", c.SessionTimeout) + return perrors.WithMessagef(err, "time.ParseDuration(SessionTimeout{%#v})", c.SessionTimeout) } if c.failFastTimeout, err = time.ParseDuration(c.FailFastTimeout); err != nil { - return errors.WithMessagef(err, "time.ParseDuration(FailFastTimeout{%#v})", c.FailFastTimeout) + return perrors.WithMessagef(err, "time.ParseDuration(FailFastTimeout{%#v})", c.FailFastTimeout) } - return errors.WithStack(c.GettySessionParam.CheckValidity()) + return perrors.WithStack(c.GettySessionParam.CheckValidity()) } diff --git a/protocol/dubbo/dubbo_invoker.go b/protocol/dubbo/dubbo_invoker.go index a3856ef0c4ca77cc108921cdccc052fd44773c20..ada7f78542102869b26f459f82a47bbc847c5ffa 100644 --- a/protocol/dubbo/dubbo_invoker.go +++ b/protocol/dubbo/dubbo_invoker.go @@ -21,7 +21,7 @@ import ( import ( log "github.com/AlexStocks/log4go" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" ) import ( @@ -31,7 +31,7 @@ import ( invocation_impl "github.com/dubbo/go-for-apache-dubbo/protocol/invocation" ) -var Err_No_Reply = errors.New("request need @reply") +var Err_No_Reply = perrors.New("request need @reply") type DubboInvoker struct { protocol.BaseInvoker diff --git a/protocol/dubbo/listener.go b/protocol/dubbo/listener.go index 0d4988dd0f1e2daa903c981b8490fabc2742e619..a1268497e1e07174d4af7100e43e5c1ebbc44a32 100644 --- a/protocol/dubbo/listener.go +++ b/protocol/dubbo/listener.go @@ -25,7 +25,7 @@ import ( "github.com/AlexStocks/getty" log "github.com/AlexStocks/log4go" "github.com/dubbogo/hessian2" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" ) import ( @@ -39,7 +39,7 @@ import ( const WritePkg_Timeout = 5 * time.Second var ( - errTooManySessions = errors.New("too many sessions") + errTooManySessions = perrors.New("too many sessions") ) type rpcSession struct { @@ -109,7 +109,7 @@ func (h *RpcClientHandler) OnCron(session getty.Session) { rpcSession, err := h.conn.getClientRpcSession(session) if err != nil { log.Error("client.getClientSession(session{%s}) = error{%v}", - session.Stat(), errors.Cause(err)) + session.Stat(), perrors.WithStack(err)) return } if h.conn.pool.rpcClient.conf.sessionTimeout.Nanoseconds() < time.Since(session.GetActive()).Nanoseconds() { @@ -151,7 +151,7 @@ func (h *RpcServerHandler) OnOpen(session getty.Session) error { } h.rwlock.RUnlock() if err != nil { - return errors.WithStack(err) + return perrors.WithStack(err) } log.Info("got session:%s", session.Stat()) @@ -266,8 +266,8 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) { log.Error("callService panic: %#v", err) req.Body = e.(error) } else if err, ok := e.(string); ok { - log.Error("callService panic: %#v", errors.New(err)) - req.Body = errors.New(err) + log.Error("callService panic: %#v", perrors.New(err)) + req.Body = perrors.New(err) } else { log.Error("callService panic: %#v", e) req.Body = e @@ -279,7 +279,7 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) { if svcIf == nil { log.Error("service not found!") req.Header.ResponseStatus = hessian.Response_SERVICE_NOT_FOUND - req.Body = errors.New("service not found") + req.Body = perrors.New("service not found") return } svc := svcIf.(*common.Service) @@ -287,7 +287,7 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) { if method == nil { log.Error("method not found!") req.Header.ResponseStatus = hessian.Response_SERVICE_NOT_FOUND - req.Body = errors.New("method not found") + req.Body = perrors.New("method not found") return } @@ -333,6 +333,6 @@ func (h *RpcServerHandler) reply(session getty.Session, req *DubboPackage, tp he } if err := session.WritePkg(resp, WritePkg_Timeout); err != nil { - log.Error("WritePkg error: %#v, %#v", errors.WithStack(err), req.Header) + log.Error("WritePkg error: %#v, %#v", perrors.WithStack(err), req.Header) } } diff --git a/protocol/dubbo/pool.go b/protocol/dubbo/pool.go index e75594467c20357b1e815a49e1d40bded4653826..28b5987a1a4fca207b6c96f3c06adf9637cdfef2 100644 --- a/protocol/dubbo/pool.go +++ b/protocol/dubbo/pool.go @@ -26,7 +26,7 @@ import ( import ( "github.com/AlexStocks/getty" log "github.com/AlexStocks/log4go" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" ) type gettyRPCClient struct { @@ -43,7 +43,7 @@ type gettyRPCClient struct { } var ( - errClientPoolClosed = errors.New("client pool closed") + errClientPoolClosed = perrors.New("client pool closed") ) func newGettyRPCClientConn(pool *gettyRPCClientPool, protocol, addr string) (*gettyRPCClient, error) { @@ -66,7 +66,7 @@ func newGettyRPCClientConn(pool *gettyRPCClientPool, protocol, addr string) (*ge } if idx > 5000 { - return nil, errors.New(fmt.Sprintf("failed to create client connection to %s in 5 seconds", addr)) + return nil, perrors.New(fmt.Sprintf("failed to create client connection to %s in 5 seconds", addr)) } time.Sleep(1e6) } @@ -203,7 +203,7 @@ func (c *gettyRPCClient) getClientRpcSession(session getty.Session) (rpcSession, } } - return rpcSession, errors.WithStack(err) + return rpcSession, perrors.WithStack(err) } func (c *gettyRPCClient) isAvailable() bool { @@ -215,7 +215,7 @@ func (c *gettyRPCClient) isAvailable() bool { } func (c *gettyRPCClient) close() error { - err := errors.Errorf("close gettyRPCClient{%#v} again", c) + err := perrors.Errorf("close gettyRPCClient{%#v} again", c) c.once.Do(func() { // delete @c from client pool c.pool.remove(c) diff --git a/protocol/dubbo/readwriter.go b/protocol/dubbo/readwriter.go index 9fa86bf30321720807b1c9b1e89c55d74d6caa3f..b7bf0e93af7c42525ecc948d5684f14a076f9827 100644 --- a/protocol/dubbo/readwriter.go +++ b/protocol/dubbo/readwriter.go @@ -22,7 +22,7 @@ import ( import ( "github.com/AlexStocks/getty" log "github.com/AlexStocks/log4go" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" ) import ( "github.com/dubbo/go-for-apache-dubbo/common" @@ -49,7 +49,7 @@ func (p *RpcClientPackageHandler) Read(ss getty.Session, data []byte) (interface buf := bytes.NewBuffer(data) err := pkg.Unmarshal(buf, p.client) if err != nil { - pkg.Err = errors.WithStack(err) // client will get this err + pkg.Err = perrors.WithStack(err) // client will get this err return pkg, len(data), nil } @@ -60,16 +60,16 @@ func (p *RpcClientPackageHandler) Write(ss getty.Session, pkg interface{}) error req, ok := pkg.(*DubboPackage) if !ok { log.Error("illegal pkg:%+v\n", pkg) - return errors.New("invalid rpc request") + return perrors.New("invalid rpc request") } buf, err := req.Marshal() if err != nil { - log.Warn("binary.Write(req{%#v}) = err{%#v}", req, errors.Cause(err)) - return errors.WithStack(err) + log.Warn("binary.Write(req{%#v}) = err{%#v}", req, perrors.WithStack(err)) + return perrors.WithStack(err) } - return errors.WithStack(ss.WriteBytes(buf.Bytes())) + return perrors.WithStack(ss.WriteBytes(buf.Bytes())) } //////////////////////////////////////////// @@ -91,7 +91,7 @@ func (p *RpcServerPackageHandler) Read(ss getty.Session, data []byte) (interface buf := bytes.NewBuffer(data) err := pkg.Unmarshal(buf) if err != nil { - return nil, 0, errors.WithStack(err) + return nil, 0, perrors.WithStack(err) } // convert params of request req := pkg.Body.([]interface{}) // length of body should be 7 @@ -137,14 +137,14 @@ func (p *RpcServerPackageHandler) Write(ss getty.Session, pkg interface{}) error res, ok := pkg.(*DubboPackage) if !ok { log.Error("illegal pkg:%+v\n, it is %+v", pkg, reflect.TypeOf(pkg)) - return errors.New("invalid rpc response") + return perrors.New("invalid rpc response") } buf, err := res.Marshal() if err != nil { - log.Warn("binary.Write(res{%#v}) = err{%#v}", res, errors.Cause(err)) - return errors.WithStack(err) + log.Warn("binary.Write(res{%#v}) = err{%#v}", res, perrors.WithStack(err)) + return perrors.WithStack(err) } - return errors.WithStack(ss.WriteBytes(buf.Bytes())) + return perrors.WithStack(ss.WriteBytes(buf.Bytes())) } diff --git a/protocol/jsonrpc/http.go b/protocol/jsonrpc/http.go index 68e18f889bcaf6cc1f7495f22b19c6befd40a0c1..60257ce027c1434bfd5cc06249f380d3511957dd 100644 --- a/protocol/jsonrpc/http.go +++ b/protocol/jsonrpc/http.go @@ -30,7 +30,7 @@ import ( ) import ( - "github.com/pkg/errors" + perrors "github.com/pkg/errors" ) import ( @@ -130,15 +130,15 @@ func (c *HTTPClient) Call(ctx context.Context, service common.URL, req *Request, } reqBody, err := codec.Write(&codecData) if err != nil { - return errors.WithStack(err) + return perrors.WithStack(err) } rspBody, err := c.Do(service.Location, service.Params.Get("interface"), httpHeader, reqBody) if err != nil { - return errors.WithStack(err) + return perrors.WithStack(err) } - return errors.WithStack(codec.Read(rspBody, rsp)) + return perrors.WithStack(codec.Read(rspBody, rsp)) } // !!The high level of complexity and the likelihood that the fasthttp client has not been extensively used @@ -148,19 +148,19 @@ func (c *HTTPClient) Do(addr, path string, httpHeader http.Header, body []byte) u := url.URL{Host: strings.TrimSuffix(addr, ":"), Path: path} httpReq, err := http.NewRequest("POST", u.String(), bytes.NewBuffer(body)) if err != nil { - return nil, errors.WithStack(err) + return nil, perrors.WithStack(err) } httpReq.Header = httpHeader httpReq.Close = true reqBuf := bytes.NewBuffer(make([]byte, 0)) if err := httpReq.Write(reqBuf); err != nil { - return nil, errors.WithStack(err) + return nil, perrors.WithStack(err) } tcpConn, err := net.DialTimeout("tcp", addr, c.options.HandshakeTimeout) if err != nil { - return nil, errors.WithStack(err) + return nil, perrors.WithStack(err) } defer tcpConn.Close() setNetConnTimeout := func(conn net.Conn, timeout time.Duration) { @@ -174,22 +174,22 @@ func (c *HTTPClient) Do(addr, path string, httpHeader http.Header, body []byte) setNetConnTimeout(tcpConn, c.options.HTTPTimeout) if _, err := reqBuf.WriteTo(tcpConn); err != nil { - return nil, errors.WithStack(err) + return nil, perrors.WithStack(err) } httpRsp, err := http.ReadResponse(bufio.NewReader(tcpConn), httpReq) if err != nil { - return nil, errors.WithStack(err) + return nil, perrors.WithStack(err) } defer httpRsp.Body.Close() b, err := ioutil.ReadAll(httpRsp.Body) if err != nil { - return nil, errors.WithStack(err) + return nil, perrors.WithStack(err) } if httpRsp.StatusCode != http.StatusOK { - return nil, errors.New(fmt.Sprintf("http status:%q, error string:%q", httpRsp.Status, string(b))) + return nil, perrors.New(fmt.Sprintf("http status:%q, error string:%q", httpRsp.Status, string(b))) } return b, nil diff --git a/protocol/jsonrpc/http_test.go b/protocol/jsonrpc/http_test.go index 030cd609b4e12ae6a61547b9971af0823f0e143d..11db1f9cd9380d1e86398b9b3021371bd9ab1199 100644 --- a/protocol/jsonrpc/http_test.go +++ b/protocol/jsonrpc/http_test.go @@ -22,7 +22,7 @@ import ( ) import ( - "github.com/pkg/errors" + perrors "github.com/pkg/errors" "github.com/stretchr/testify/assert" ) @@ -118,7 +118,7 @@ func (u *UserProvider) GetUser0(req []interface{}, rsp *User) error { } func (u *UserProvider) GetUser1(ctx context.Context, req []interface{}, rsp *User) error { - return errors.New("error") + return perrors.New("error") } func (u *UserProvider) Service() string { diff --git a/protocol/jsonrpc/json.go b/protocol/jsonrpc/json.go index d82b00f69ac2f8542cd3c6ec54a050f05dddd370..c5c26d3f93172f563bb89642ef0664c904c3e4e8 100644 --- a/protocol/jsonrpc/json.go +++ b/protocol/jsonrpc/json.go @@ -24,7 +24,7 @@ import ( ) import ( - "github.com/pkg/errors" + perrors "github.com/pkg/errors" ) const ( @@ -140,10 +140,10 @@ func (c *jsonClientCodec) Write(d *CodecData) ([]byte, error) { } case reflect.Array, reflect.Struct: default: - return nil, errors.New("unsupported param type: Ptr to " + k.String()) + return nil, perrors.New("unsupported param type: Ptr to " + k.String()) } default: - return nil, errors.New("unsupported param type: " + k.String()) + return nil, perrors.New("unsupported param type: " + k.String()) } } @@ -158,7 +158,7 @@ func (c *jsonClientCodec) Write(d *CodecData) ([]byte, error) { defer buf.Reset() enc := json.NewEncoder(buf) if err := enc.Encode(&c.req); err != nil { - return nil, errors.WithStack(err) + return nil, perrors.WithStack(err) } return buf.Bytes(), nil @@ -172,24 +172,24 @@ func (c *jsonClientCodec) Read(streamBytes []byte, x interface{}) error { dec := json.NewDecoder(buf) if err := dec.Decode(&c.rsp); err != nil { if err != io.EOF { - err = errors.WithStack(err) + err = perrors.WithStack(err) } return err } _, ok := c.pending[c.rsp.ID] if !ok { - err := errors.Errorf("can not find method of rsponse id %v, rsponse error:%v", c.rsp.ID, c.rsp.Error) + err := perrors.Errorf("can not find method of rsponse id %v, rsponse error:%v", c.rsp.ID, c.rsp.Error) return err } delete(c.pending, c.rsp.ID) // c.rsp.ID if c.rsp.Error != nil { - return errors.New(c.rsp.Error.Error()) + return perrors.New(c.rsp.Error.Error()) } - return errors.WithStack(json.Unmarshal(*c.rsp.Result, x)) + return perrors.WithStack(json.Unmarshal(*c.rsp.Result, x)) } ////////////////////////////////////////// @@ -221,32 +221,32 @@ func (r *serverRequest) UnmarshalJSON(raw []byte) error { // Attention: if do not define a new struct named @req, the json.Unmarshal will invoke // (*serverRequest)UnmarshalJSON recursively. if err := json.Unmarshal(raw, req(r)); err != nil { - return errors.New("bad request") + return perrors.New("bad request") } var o = make(map[string]*json.RawMessage) if err := json.Unmarshal(raw, &o); err != nil { - return errors.New("bad request") + return perrors.New("bad request") } if o["jsonrpc"] == nil || o["method"] == nil { - return errors.New("bad request") + return perrors.New("bad request") } _, okID := o["id"] _, okParams := o["params"] if len(o) == 3 && !(okID || okParams) || len(o) == 4 && !(okID && okParams) || len(o) > 4 { - return errors.New("bad request") + return perrors.New("bad request") } if r.Version != Version { - return errors.New("bad request") + return perrors.New("bad request") } if okParams { if r.Params == nil || len(*r.Params) == 0 { - return errors.New("bad request") + return perrors.New("bad request") } switch []byte(*r.Params)[0] { case '[', '{': default: - return errors.New("bad request") + return perrors.New("bad request") } } if okID && r.ID == nil { @@ -254,11 +254,11 @@ func (r *serverRequest) UnmarshalJSON(raw []byte) error { } if okID { if len(*r.ID) == 0 { - return errors.New("bad request") + return perrors.New("bad request") } switch []byte(*r.ID)[0] { case 't', 'f', '{', '[': - return errors.New("bad request") + return perrors.New("bad request") } } @@ -394,7 +394,7 @@ func (c *ServerCodec) Write(errMsg string, x interface{}) ([]byte, error) { defer buf.Reset() enc := json.NewEncoder(buf) if err := enc.Encode(resp); err != nil { - return nil, errors.WithStack(err) + return nil, perrors.WithStack(err) } return buf.Bytes(), nil diff --git a/protocol/jsonrpc/server.go b/protocol/jsonrpc/server.go index aa02a9b1982a165ec4decf999892b288e3185d7a..c514bfcdc11809004cf5ae0054acc2bbf6680df4 100644 --- a/protocol/jsonrpc/server.go +++ b/protocol/jsonrpc/server.go @@ -31,7 +31,7 @@ import ( import ( log "github.com/AlexStocks/log4go" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" ) import ( @@ -105,10 +105,10 @@ func (s *Server) handlePkg(conn net.Conn) { rspBuf.Reset() err := rsp.Write(rspBuf) if err != nil { - return errors.WithStack(err) + return perrors.WithStack(err) } _, err = rspBuf.WriteTo(conn) - return errors.WithStack(err) + return perrors.WithStack(err) } for { @@ -140,9 +140,9 @@ func (s *Server) handlePkg(conn net.Conn) { if contentType != "application/json" && contentType != "application/json-rpc" { setTimeout(conn, httpTimeout) r.Header.Set("Content-Type", "text/plain") - if errRsp := sendErrorResp(r.Header, []byte(errors.Cause(err).Error())); errRsp != nil { + if errRsp := sendErrorResp(r.Header, []byte(perrors.WithStack(err).Error())); errRsp != nil { log.Warn("sendErrorResp(header:%#v, error:%v) = error:%s", - r.Header, errors.Cause(err), errRsp) + r.Header, perrors.WithStack(err), errRsp) } return } @@ -159,9 +159,9 @@ func (s *Server) handlePkg(conn net.Conn) { setTimeout(conn, httpTimeout) if err := serveRequest(ctx, reqHeader, reqBody, conn, s.exporter); err != nil { - if errRsp := sendErrorResp(r.Header, []byte(errors.Cause(err).Error())); errRsp != nil { + if errRsp := sendErrorResp(r.Header, []byte(perrors.WithStack(err).Error())); errRsp != nil { log.Warn("sendErrorResp(header:%#v, error:%v) = error:%s", - r.Header, errors.Cause(err), errRsp) + r.Header, perrors.WithStack(err), errRsp) } log.Info("Unexpected error serving request, closing socket: %v", err) @@ -193,7 +193,7 @@ func accept(listener net.Listener, fn func(net.Conn)) error { time.Sleep(tmpDelay) continue } - return errors.WithStack(err) + return perrors.WithStack(err) } go func() { @@ -266,10 +266,10 @@ func serveRequest(ctx context.Context, rspBuf.Reset() err := rsp.Write(rspBuf) if err != nil { - return errors.WithStack(err) + return perrors.WithStack(err) } _, err = rspBuf.WriteTo(conn) - return errors.WithStack(err) + return perrors.WithStack(err) } sendResp := func(header map[string]string, body []byte) error { @@ -290,10 +290,10 @@ func serveRequest(ctx context.Context, rspBuf.Reset() err := rsp.Write(rspBuf) if err != nil { - return errors.WithStack(err) + return perrors.WithStack(err) } _, err = rspBuf.WriteTo(conn) - return errors.WithStack(err) + return perrors.WithStack(err) } // read request header @@ -301,22 +301,22 @@ func serveRequest(ctx context.Context, err := codec.ReadHeader(header, body) if err != nil { if err == io.EOF || err == io.ErrUnexpectedEOF { - return errors.WithStack(err) + return perrors.WithStack(err) } - return errors.New("server cannot decode request: " + err.Error()) + return perrors.New("server cannot decode request: " + err.Error()) } serviceName := header["Path"] methodName := codec.req.Method if len(serviceName) == 0 || len(methodName) == 0 { codec.ReadBody(nil) - return errors.New("service/method request ill-formed: " + serviceName + "/" + methodName) + return perrors.New("service/method request ill-formed: " + serviceName + "/" + methodName) } // read body var args interface{} if err = codec.ReadBody(&args); err != nil { - return errors.WithStack(err) + return perrors.WithStack(err) } log.Debug("args: %v", args) @@ -333,18 +333,18 @@ func serveRequest(ctx context.Context, if errRsp := sendErrorResp(header, []byte(err.Error())); errRsp != nil { log.Warn("Exporter: sendErrorResp(header:%#v, error:%v) = error:%s", header, err, errRsp) - return errors.WithStack(errRsp) + return perrors.WithStack(errRsp) } } if res := result.Result(); res != nil { rspStream, err := codec.Write("", res) if err != nil { - return errors.WithStack(err) + return perrors.WithStack(err) } if errRsp := sendResp(header, rspStream); errRsp != nil { log.Warn("Exporter: sendResp(header:%#v, error:%v) = error:%s", header, err, errRsp) - return errors.WithStack(errRsp) + return perrors.WithStack(errRsp) } } } @@ -352,11 +352,11 @@ func serveRequest(ctx context.Context, // get method svc := common.ServiceMap.GetService(JSONRPC, serviceName) if svc == nil { - return errors.New("cannot find svc " + serviceName) + return perrors.New("cannot find svc " + serviceName) } mtype := svc.Method()[methodName] if mtype == nil { - return errors.New("cannot find method " + methodName + " of svc " + serviceName) + return perrors.New("cannot find method " + methodName + " of svc " + serviceName) } replyv := reflect.New(mtype.ReplyType().Elem()) @@ -394,7 +394,7 @@ func serveRequest(ctx context.Context, } rspStream, err := codec.Write(errMsg, rspReply) if err != nil { - return errors.WithStack(err) + return perrors.WithStack(err) } rsp := &http.Response{ StatusCode: code, diff --git a/registry/directory/directory.go b/registry/directory/directory.go index 43bdaceafef268992c7708aa6c4e999711cdaaf6..256065fae007ca45c33c87c6cd2b5c120506f86a 100644 --- a/registry/directory/directory.go +++ b/registry/directory/directory.go @@ -21,7 +21,7 @@ import ( import ( log "github.com/AlexStocks/log4go" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" ) import ( @@ -61,7 +61,7 @@ func NewRegistryDirectory(url *common.URL, registry registry.Registry, opts ...O opt(&options) } if url.SubURL == nil { - return nil, errors.Errorf("url is invalid, suburl can not be nil") + return nil, perrors.Errorf("url is invalid, suburl can not be nil") } return ®istryDirectory{ BaseDirectory: directory.NewBaseDirectory(url), @@ -87,14 +87,14 @@ func (dir *registryDirectory) Subscribe(url common.URL) { log.Warn("event listener game over.") return } - log.Warn("getListener() = err:%v", errors.Cause(err)) + log.Warn("getListener() = err:%v", perrors.WithStack(err)) time.Sleep(time.Duration(RegistryConnDelay) * time.Second) continue } for { if serviceEvent, err := listener.Next(); err != nil { - log.Warn("Selector.watch() = error{%v}", errors.Cause(err)) + log.Warn("Selector.watch() = error{%v}", perrors.WithStack(err)) listener.Close() time.Sleep(time.Duration(RegistryConnDelay) * time.Second) return diff --git a/registry/zookeeper/listener.go b/registry/zookeeper/listener.go index 9727856a849975115268551de528fa1945b21a28..a2363f87d6ecdeadf4323420b97d2f4037020806 100644 --- a/registry/zookeeper/listener.go +++ b/registry/zookeeper/listener.go @@ -24,7 +24,7 @@ import ( import ( log "github.com/AlexStocks/log4go" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" "github.com/samuel/go-zookeeper/zk" ) @@ -111,7 +111,7 @@ func (l *zkEventListener) handleZkNodeEvent(zkPath string, children []string, co newChildren, err := l.client.getChildren(zkPath) if err != nil { - log.Error("path{%s} child nodes changed, zk.Children() = error{%v}", zkPath, errors.Cause(err)) + log.Error("path{%s} child nodes changed, zk.Children() = error{%v}", zkPath, perrors.WithStack(err)) return } @@ -130,7 +130,7 @@ func (l *zkEventListener) handleZkNodeEvent(zkPath string, children []string, co //context.TODO serviceURL, err = common.NewURL(context.TODO(), n) if err != nil { - log.Error("NewURL(%s) = error{%v}", n, errors.Cause(err)) + log.Error("NewURL(%s) = error{%v}", n, perrors.WithStack(err)) continue } if !conf.URLEqual(serviceURL) { @@ -166,7 +166,7 @@ func (l *zkEventListener) handleZkNodeEvent(zkPath string, children []string, co } log.Warn("delete serviceURL{%s}", serviceURL) if err != nil { - log.Error("NewURL(i{%s}) = error{%v}", n, errors.Cause(err)) + log.Error("NewURL(i{%s}) = error{%v}", n, perrors.WithStack(err)) continue } l.events <- zkEvent{®istry.ServiceEvent{Action: registry.ServiceDel, Service: serviceURL}, nil} @@ -306,16 +306,16 @@ func (l *zkEventListener) Next() (*registry.ServiceEvent, error) { select { case <-l.client.done(): log.Warn("listener's zk client connection is broken, so zk event listener exit now.") - return nil, errors.New("listener stopped") + return nil, perrors.New("listener stopped") case <-l.registry.done: log.Warn("zk consumer register has quit, so zk event listener exit asap now.") - return nil, errors.New("listener stopped") + return nil, perrors.New("listener stopped") case e := <-l.events: log.Debug("got zk event %s", e) if e.err != nil { - return nil, errors.WithStack(e.err) + return nil, perrors.WithStack(e.err) } if e.res.Action == registry.ServiceDel && !l.valid() { log.Warn("update @result{%s}. But its connection to registry is invalid", e.res) diff --git a/registry/zookeeper/registry.go b/registry/zookeeper/registry.go index 10173132b3cf314ef52c2456bfd7a1b46f474379..69a02c06db06cd3c3bb7260bbd108010a2c20c66 100644 --- a/registry/zookeeper/registry.go +++ b/registry/zookeeper/registry.go @@ -27,7 +27,7 @@ import ( import ( log "github.com/AlexStocks/log4go" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" "github.com/samuel/go-zookeeper/zk" ) @@ -175,13 +175,13 @@ func (r *zkRegistry) validateZookeeperClient() error { if err != nil { log.Error("timeout config %v is invalid ,err is %v", r.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT), err.Error()) - return errors.WithMessagef(err, "newZookeeperClient(address:%+v)", r.Location) + return perrors.WithMessagef(err, "newZookeeperClient(address:%+v)", r.Location) } r.client, err = newZookeeperClient(RegistryZkClient, []string{r.Location}, timeout) if err != nil { log.Warn("newZookeeperClient(name{%s}, zk addresss{%v}, timeout{%d}) = error{%v}", RegistryZkClient, r.Location, timeout.String(), err) - return errors.WithMessagef(err, "newZookeeperClient(address:%+v)", r.Location) + return perrors.WithMessagef(err, "newZookeeperClient(address:%+v)", r.Location) } } if r.client.conn == nil { @@ -193,7 +193,7 @@ func (r *zkRegistry) validateZookeeperClient() error { } } - return errors.WithMessagef(err, "newZookeeperClient(address:%+v)", r.PrimitiveURL) + return perrors.WithMessagef(err, "newZookeeperClient(address:%+v)", r.PrimitiveURL) } func (r *zkRegistry) handleZkRestart() { @@ -229,7 +229,7 @@ LOOP: } err = r.validateZookeeperClient() log.Info("ZkProviderRegistry.validateZookeeperClient(zkAddr{%s}) = error{%#v}", - r.client.zkAddrs, errors.Cause(err)) + r.client.zkAddrs, perrors.WithStack(err)) if err == nil { // copy r.services services := []common.URL{} @@ -242,7 +242,7 @@ LOOP: err = r.register(confIf) if err != nil { log.Error("(ZkProviderRegistry)register(conf{%#v}) = error{%#v}", - confIf, errors.Cause(err)) + confIf, perrors.WithStack(err)) flag = false break } @@ -275,12 +275,12 @@ func (r *zkRegistry) Register(conf common.URL) error { _, ok = r.services[conf.Key()] r.cltLock.Unlock() if ok { - return errors.Errorf("Path{%s} has been registered", conf.Path) + return perrors.Errorf("Path{%s} has been registered", conf.Path) } err = r.register(conf) if err != nil { - return errors.WithStack(err) + return perrors.WithStack(err) } r.cltLock.Lock() @@ -304,12 +304,12 @@ func (r *zkRegistry) Register(conf common.URL) error { _, ok = r.services[conf.Key()] r.cltLock.Unlock() if ok { - return errors.Errorf("Path{%s} has been registered", conf.Key()) + return perrors.Errorf("Path{%s} has been registered", conf.Key()) } err = r.register(conf) if err != nil { - return errors.WithMessagef(err, "register(conf:%+v)", conf) + return perrors.WithMessagef(err, "register(conf:%+v)", conf) } r.cltLock.Lock() @@ -336,7 +336,7 @@ func (r *zkRegistry) register(c common.URL) error { err = r.validateZookeeperClient() if err != nil { - return errors.WithStack(err) + return perrors.WithStack(err) } params = url.Values{} for k, v := range c.Params { @@ -353,7 +353,7 @@ func (r *zkRegistry) register(c common.URL) error { case common.PROVIDER: if c.Path == "" || len(c.Methods) == 0 { - return errors.Errorf("conf{Path:%s, Methods:%s}", c.Path, c.Methods) + return perrors.Errorf("conf{Path:%s, Methods:%s}", c.Path, c.Methods) } // 先创建服务下面的provider node dubboPath = fmt.Sprintf("/dubbo%s/%s", c.Path, common.DubboNodes[common.PROVIDER]) @@ -361,8 +361,8 @@ func (r *zkRegistry) register(c common.URL) error { err = r.client.Create(dubboPath) r.cltLock.Unlock() if err != nil { - log.Error("zkClient.create(path{%s}) = error{%#v}", dubboPath, errors.Cause(err)) - return errors.WithMessagef(err, "zkclient.Create(path:%s)", dubboPath) + log.Error("zkClient.create(path{%s}) = error{%#v}", dubboPath, perrors.WithStack(err)) + return perrors.WithMessagef(err, "zkclient.Create(path:%s)", dubboPath) } params.Add("anyhost", "true") @@ -403,16 +403,16 @@ func (r *zkRegistry) register(c common.URL) error { err = r.client.Create(dubboPath) r.cltLock.Unlock() if err != nil { - log.Error("zkClient.create(path{%s}) = error{%v}", dubboPath, errors.Cause(err)) - return errors.WithStack(err) + log.Error("zkClient.create(path{%s}) = error{%v}", dubboPath, perrors.WithStack(err)) + return perrors.WithStack(err) } dubboPath = fmt.Sprintf("/dubbo%s/%s", c.Path, common.DubboNodes[common.PROVIDER]) r.cltLock.Lock() err = r.client.Create(dubboPath) r.cltLock.Unlock() if err != nil { - log.Error("zkClient.create(path{%s}) = error{%v}", dubboPath, errors.Cause(err)) - return errors.WithStack(err) + log.Error("zkClient.create(path{%s}) = error{%v}", dubboPath, perrors.WithStack(err)) + return perrors.WithStack(err) } params.Add("protocol", c.Protocol) @@ -426,13 +426,13 @@ func (r *zkRegistry) register(c common.URL) error { dubboPath = fmt.Sprintf("/dubbo%s/%s", c.Path, (common.RoleType(common.CONSUMER)).String()) log.Debug("consumer path:%s, url:%s", dubboPath, rawURL) default: - return errors.Errorf("@c{%v} type is not referencer or provider", c) + return perrors.Errorf("@c{%v} type is not referencer or provider", c) } err = r.registerTempZookeeperNode(dubboPath, encodedURL) if err != nil { - return errors.WithMessagef(err, "registerTempZookeeperNode(path:%s, url:%s)", dubboPath, rawURL) + return perrors.WithMessagef(err, "registerTempZookeeperNode(path:%s, url:%s)", dubboPath, rawURL) } return nil } @@ -447,13 +447,13 @@ func (r *zkRegistry) registerTempZookeeperNode(root string, node string) error { defer r.cltLock.Unlock() err = r.client.Create(root) if err != nil { - log.Error("zk.Create(root{%s}) = err{%v}", root, errors.Cause(err)) - return errors.WithStack(err) + log.Error("zk.Create(root{%s}) = err{%v}", root, perrors.WithStack(err)) + return perrors.WithStack(err) } zkPath, err = r.client.RegisterTemp(root, node) if err != nil { - log.Error("RegisterTempNode(root{%s}, node{%s}) = error{%v}", root, node, errors.Cause(err)) - return errors.WithMessagef(err, "RegisterTempNode(root{%s}, node{%s})", root, node) + log.Error("RegisterTempNode(root{%s}, node{%s}) = error{%v}", root, node, perrors.WithStack(err)) + return perrors.WithMessagef(err, "RegisterTempNode(root{%s}, node{%s})", root, node) } log.Debug("create a zookeeper node:%s", zkPath) @@ -481,7 +481,7 @@ func (r *zkRegistry) getListener(conf common.URL) (*zkEventListener, error) { client := r.client r.cltLock.Unlock() if client == nil { - return nil, errors.New("zk connection broken") + return nil, perrors.New("zk connection broken") } // new client & listener diff --git a/registry/zookeeper/zk_client.go b/registry/zookeeper/zk_client.go index 341142027ccac8329ed10cc1a0c96b60b86b44fd..00d2a0264cb5b692d064388dd8e7c39f152a7b37 100644 --- a/registry/zookeeper/zk_client.go +++ b/registry/zookeeper/zk_client.go @@ -23,12 +23,12 @@ import ( import ( log "github.com/AlexStocks/log4go" - "github.com/pkg/errors" + perrors "github.com/pkg/errors" "github.com/samuel/go-zookeeper/zk" ) var ( - errNilZkClientConn = errors.New("zookeeperclient{conn} is nil") + errNilZkClientConn = perrors.New("zookeeperclient{conn} is nil") ) type zookeeperClient struct { @@ -94,7 +94,7 @@ func newZookeeperClient(name string, zkAddrs []string, timeout time.Duration) (* // connect to zookeeper z.conn, event, err = zk.Connect(zkAddrs, timeout) if err != nil { - return nil, errors.WithMessagef(err, "zk.Connect(zkAddrs:%+v)", zkAddrs) + return nil, perrors.WithMessagef(err, "zk.Connect(zkAddrs:%+v)", zkAddrs) } z.wait.Add(1) @@ -120,7 +120,7 @@ func newMockZookeeperClient(name string, timeout time.Duration) (*zk.TestCluster ts, err := zk.StartTestCluster(1, nil, nil) if err != nil { - return nil, nil, nil, errors.WithMessagef(err, "zk.Connect") + return nil, nil, nil, perrors.WithMessagef(err, "zk.Connect") } //callbackChan := make(chan zk.Event) @@ -130,7 +130,7 @@ func newMockZookeeperClient(name string, timeout time.Duration) (*zk.TestCluster z.conn, event, err = ts.ConnectWithOptions(timeout) if err != nil { - return nil, nil, nil, errors.WithMessagef(err, "zk.Connect") + return nil, nil, nil, perrors.WithMessagef(err, "zk.Connect") } //z.wait.Add(1) @@ -304,8 +304,8 @@ func (z *zookeeperClient) Create(basePath string) error { if err == zk.ErrNodeExists { log.Error("zk.create(\"%s\") exists\n", tmpPath) } else { - log.Error("zk.create(\"%s\") error(%v)\n", tmpPath, errors.Cause(err)) - return errors.WithMessagef(err, "zk.Create(path:%s)", basePath) + log.Error("zk.create(\"%s\") error(%v)\n", tmpPath, perrors.WithStack(err)) + return perrors.WithMessagef(err, "zk.Create(path:%s)", basePath) } } } @@ -325,7 +325,7 @@ func (z *zookeeperClient) Delete(basePath string) error { } z.Unlock() - return errors.WithMessagef(err, "Delete(basePath:%s)", basePath) + return perrors.WithMessagef(err, "Delete(basePath:%s)", basePath) } func (z *zookeeperClient) RegisterTemp(basePath string, node string) (string, error) { @@ -346,8 +346,8 @@ func (z *zookeeperClient) RegisterTemp(basePath string, node string) (string, er z.Unlock() //if err != nil && err != zk.ErrNodeExists { if err != nil { - log.Warn("conn.Create(\"%s\", zk.FlagEphemeral) = error(%v)\n", zkPath, errors.Cause(err)) - return "", errors.WithStack(err) + log.Warn("conn.Create(\"%s\", zk.FlagEphemeral) = error(%v)\n", zkPath, perrors.WithStack(err)) + return "", perrors.WithStack(err) } log.Debug("zkClient{%s} create a temp zookeeper node:%s\n", z.name, tmpPath) @@ -375,7 +375,7 @@ func (z *zookeeperClient) RegisterTempSeq(basePath string, data []byte) (string, if err != nil && err != zk.ErrNodeExists { log.Error("zkClient{%s} conn.Create(\"%s\", \"%s\", zk.FlagEphemeral|zk.FlagSequence) error(%v)\n", z.name, basePath, string(data), err) - return "", errors.WithStack(err) + return "", perrors.WithStack(err) } log.Debug("zkClient{%s} create a temp zookeeper node:%s\n", z.name, tmpPath) @@ -398,16 +398,16 @@ func (z *zookeeperClient) getChildrenW(path string) ([]string, <-chan zk.Event, z.Unlock() if err != nil { if err == zk.ErrNoNode { - return nil, nil, errors.Errorf("path{%s} has none children", path) + return nil, nil, perrors.Errorf("path{%s} has none children", path) } log.Error("zk.ChildrenW(path{%s}) = error(%v)", path, err) - return nil, nil, errors.WithMessagef(err, "zk.ChildrenW(path:%s)", path) + return nil, nil, perrors.WithMessagef(err, "zk.ChildrenW(path:%s)", path) } if stat == nil { - return nil, nil, errors.Errorf("path{%s} has none children", path) + return nil, nil, perrors.Errorf("path{%s} has none children", path) } if len(children) == 0 { - return nil, nil, errors.Errorf("path{%s} has none children", path) + return nil, nil, perrors.Errorf("path{%s} has none children", path) } return children, event, nil @@ -428,16 +428,16 @@ func (z *zookeeperClient) getChildren(path string) ([]string, error) { z.Unlock() if err != nil { if err == zk.ErrNoNode { - return nil, errors.Errorf("path{%s} has none children", path) + return nil, perrors.Errorf("path{%s} has none children", path) } - log.Error("zk.Children(path{%s}) = error(%v)", path, errors.Cause(err)) - return nil, errors.WithMessagef(err, "zk.Children(path:%s)", path) + log.Error("zk.Children(path{%s}) = error(%v)", path, perrors.WithStack(err)) + return nil, perrors.WithMessagef(err, "zk.Children(path:%s)", path) } if stat == nil { - return nil, errors.Errorf("path{%s} has none children", path) + return nil, perrors.Errorf("path{%s} has none children", path) } if len(children) == 0 { - return nil, errors.Errorf("path{%s} has none children", path) + return nil, perrors.Errorf("path{%s} has none children", path) } return children, nil @@ -457,12 +457,12 @@ func (z *zookeeperClient) existW(zkPath string) (<-chan zk.Event, error) { } z.Unlock() if err != nil { - log.Error("zkClient{%s}.ExistsW(path{%s}) = error{%v}.", z.name, zkPath, errors.Cause(err)) - return nil, errors.WithMessagef(err, "zk.ExistsW(path:%s)", zkPath) + log.Error("zkClient{%s}.ExistsW(path{%s}) = error{%v}.", z.name, zkPath, perrors.WithStack(err)) + return nil, perrors.WithMessagef(err, "zk.ExistsW(path:%s)", zkPath) } if !exist { log.Warn("zkClient{%s}'s App zk path{%s} does not exist.", z.name, zkPath) - return nil, errors.Errorf("zkClient{%s} App zk path{%s} does not exist.", z.name, zkPath) + return nil, perrors.Errorf("zkClient{%s} App zk path{%s} does not exist.", z.name, zkPath) } return event, nil