mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 01:30:25 +08:00
add more clear error when rpc service is not started
This commit is contained in:
parent
17a0908a84
commit
0dd8e27557
@ -2,7 +2,9 @@ package internal
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tal-tech/go-zero/zrpc/internal/balancer/p2c"
|
"github.com/tal-tech/go-zero/zrpc/internal/balancer/p2c"
|
||||||
@ -11,7 +13,10 @@ import (
|
|||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
const dialTimeout = time.Second * 3
|
const (
|
||||||
|
dialTimeout = time.Second * 3
|
||||||
|
separator = '/'
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
resolver.RegisterResolver()
|
resolver.RegisterResolver()
|
||||||
@ -83,7 +88,16 @@ func dial(server string, opts ...ClientOption) (*grpc.ClientConn, error) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
conn, err := grpc.DialContext(timeCtx, server, options...)
|
conn, err := grpc.DialContext(timeCtx, server, options...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("rpc dial: %s, error: %s", server, err.Error())
|
service := server
|
||||||
|
if errors.Is(err, context.DeadlineExceeded) {
|
||||||
|
pos := strings.LastIndexByte(server, separator)
|
||||||
|
// len(server) - 1 is the index of last char
|
||||||
|
if 0 < pos && pos < len(server)-1 {
|
||||||
|
service = server[pos+1:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("rpc dial: %s, error: %s, make sure rpc service %q is alread started",
|
||||||
|
server, err.Error(), service)
|
||||||
}
|
}
|
||||||
|
|
||||||
return conn, nil
|
return conn, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user