centralize harded-code message

Signed-off-by: Fahed Dorgaa <fahed.dorgaa@gmail.com>
This commit is contained in:
Fahed Dorgaa
2019-07-13 15:07:23 +02:00
parent f2b6c31d0f
commit db95af43f3
6 changed files with 37 additions and 24 deletions

View File

@@ -137,7 +137,7 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
c.conn, c.connector = conn, connector
}
if copts.services == nil && c.conn == nil {
return nil, errors.New("no grpc connection or services is available")
return nil, errdefs.ErrNoGRPCAndService
}
// check namespace labels for default runtime
@@ -196,7 +196,7 @@ type Client struct {
// Reconnect re-establishes the GRPC connection to the containerd daemon
func (c *Client) Reconnect() error {
if c.connector == nil {
return errors.New("unable to reconnect to containerd, no connector available")
return errdefs.ErrReconnectFailed
}
c.connMu.Lock()
defer c.connMu.Unlock()
@@ -219,7 +219,7 @@ func (c *Client) IsServing(ctx context.Context) (bool, error) {
c.connMu.Lock()
if c.conn == nil {
c.connMu.Unlock()
return false, errors.New("no grpc connection available")
return false, errdefs.ErrNoGRPC
}
c.connMu.Unlock()
r, err := c.HealthService().Check(ctx, &grpc_health_v1.HealthCheckRequest{}, grpc.WaitForReady(true))
@@ -350,7 +350,7 @@ func (c *Client) Fetch(ctx context.Context, ref string, opts ...RemoteOpt) (imag
}
if fetchCtx.Unpack {
return images.Image{}, errors.New("unpack on fetch not supported, try pull")
return images.Image{}, errdefs.ErrUnpackNotSupported
}
if fetchCtx.PlatformMatcher == nil {
@@ -656,7 +656,7 @@ func (c *Client) Version(ctx context.Context) (Version, error) {
c.connMu.Lock()
if c.conn == nil {
c.connMu.Unlock()
return Version{}, errors.New("no grpc connection available")
return Version{}, errdefs.ErrNoGRPC
}
c.connMu.Unlock()
response, err := c.VersionService().Version(ctx, &ptypes.Empty{})