From d9f59b28fb4c54529ee09d19a28a48ef39443ba6 Mon Sep 17 00:00:00 2001
From: "vito.he" <hxmhlt@163.com>
Date: Thu, 23 May 2019 16:32:19 +0800
Subject: [PATCH] Fix: error return msg not include service name

---
 cluster/cluster_impl/failover_cluster_invoker.go |  2 +-
 cluster/directory/static_directory.go            |  7 ++++++-
 common/url.go                                    | 11 ++++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/cluster/cluster_impl/failover_cluster_invoker.go b/cluster/cluster_impl/failover_cluster_invoker.go
index d81986d02..5bb2471e0 100644
--- a/cluster/cluster_impl/failover_cluster_invoker.go
+++ b/cluster/cluster_impl/failover_cluster_invoker.go
@@ -93,7 +93,7 @@ func (invoker *failoverClusterInvoker) Invoke(invocation protocol.Invocation) pr
 		}
 	}
 	ip, _ := utils.GetLocalIP()
-	return &protocol.RPCResult{Err: perrors.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/directory/static_directory.go b/cluster/directory/static_directory.go
index 57093c4ae..3ac567b00 100644
--- a/cluster/directory/static_directory.go
+++ b/cluster/directory/static_directory.go
@@ -25,8 +25,13 @@ type staticDirectory struct {
 }
 
 func NewStaticDirectory(invokers []protocol.Invoker) *staticDirectory {
+	var url common.URL
+
+	if len(invokers) > 0 {
+		url = invokers[0].GetUrl()
+	}
 	return &staticDirectory{
-		BaseDirectory: NewBaseDirectory(&common.URL{}),
+		BaseDirectory: NewBaseDirectory(&url),
 		invokers:      invokers,
 	}
 }
diff --git a/common/url.go b/common/url.go
index 66dfaed6c..9b0c6352a 100644
--- a/common/url.go
+++ b/common/url.go
@@ -248,7 +248,16 @@ func (c URL) Context() context.Context {
 }
 
 func (c URL) Service() string {
-	return strings.TrimPrefix(c.Path, "/")
+	service := strings.TrimPrefix(c.Path, "/")
+	if service != "" {
+		return service
+	} else if c.SubURL != nil {
+		service = strings.TrimPrefix(c.SubURL.Path, "/")
+		if service != "" { //if url.path is "" then return suburl's path, special for registry Url
+			return service
+		}
+	}
+	return ""
 }
 func (c URL) GetParam(s string, d string) string {
 	var r string
-- 
GitLab