linux: Return grpc error description only

This avoid having "rpc error: code = Unknown" in the final output.

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickael Laventure
2017-06-14 08:46:53 -07:00
parent 7dbf26ecf6
commit 171759a233
2 changed files with 36 additions and 8 deletions

View File

@@ -5,11 +5,14 @@ package linux
import (
"context"
"google.golang.org/grpc"
"github.com/containerd/containerd/api/services/shim"
"github.com/containerd/containerd/api/types/task"
"github.com/containerd/containerd/plugin"
protobuf "github.com/gogo/protobuf/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
)
type Task struct {
@@ -40,13 +43,16 @@ func (c *Task) Info() plugin.TaskInfo {
func (c *Task) Start(ctx context.Context) error {
_, err := c.shim.Start(ctx, &shim.StartRequest{})
if err != nil {
err = errors.New(grpc.ErrorDesc(err))
}
return err
}
func (c *Task) State(ctx context.Context) (plugin.State, error) {
response, err := c.shim.State(ctx, &shim.StateRequest{})
if err != nil {
return plugin.State{}, err
return plugin.State{}, errors.New(grpc.ErrorDesc(err))
}
var status plugin.Status
switch response.Status {
@@ -72,11 +78,17 @@ func (c *Task) State(ctx context.Context) (plugin.State, error) {
func (c *Task) Pause(ctx context.Context) error {
_, err := c.shim.Pause(ctx, &shim.PauseRequest{})
if err != nil {
err = errors.New(grpc.ErrorDesc(err))
}
return err
}
func (c *Task) Resume(ctx context.Context) error {
_, err := c.shim.Resume(ctx, &shim.ResumeRequest{})
if err != nil {
err = errors.New(grpc.ErrorDesc(err))
}
return err
}
@@ -86,6 +98,9 @@ func (c *Task) Kill(ctx context.Context, signal uint32, pid uint32, all bool) er
Pid: pid,
All: all,
})
if err != nil {
err = errors.New(grpc.ErrorDesc(err))
}
return err
}
@@ -102,7 +117,7 @@ func (c *Task) Exec(ctx context.Context, opts plugin.ExecOpts) (plugin.Process,
}
resp, err := c.shim.Exec(ctx, request)
if err != nil {
return nil, err
return nil, errors.New(grpc.ErrorDesc(err))
}
return &Process{
@@ -115,9 +130,8 @@ func (c *Task) Processes(ctx context.Context) ([]uint32, error) {
resp, err := c.shim.Processes(ctx, &shim.ProcessesRequest{
ID: c.containerID,
})
if err != nil {
return nil, err
return nil, errors.New(grpc.ErrorDesc(err))
}
pids := make([]uint32, 0, len(resp.Processes))
@@ -135,6 +149,9 @@ func (c *Task) Pty(ctx context.Context, pid uint32, size plugin.ConsoleSize) err
Width: size.Width,
Height: size.Height,
})
if err != nil {
err = errors.New(grpc.ErrorDesc(err))
}
return err
}
@@ -142,6 +159,9 @@ func (c *Task) CloseStdin(ctx context.Context, pid uint32) error {
_, err := c.shim.CloseStdin(ctx, &shim.CloseStdinRequest{
Pid: pid,
})
if err != nil {
err = errors.New(grpc.ErrorDesc(err))
}
return err
}
@@ -155,6 +175,9 @@ func (c *Task) Checkpoint(ctx context.Context, opts plugin.CheckpointOpts) error
EmptyNamespaces: opts.EmptyNamespaces,
CheckpointPath: opts.Path,
})
if err != nil {
err = errors.New(grpc.ErrorDesc(err))
}
return err
}
@@ -163,7 +186,7 @@ func (c *Task) DeleteProcess(ctx context.Context, pid uint32) (*plugin.Exit, err
Pid: pid,
})
if err != nil {
return nil, err
return nil, errors.New(grpc.ErrorDesc(err))
}
return &plugin.Exit{
Status: r.ExitStatus,
@@ -181,6 +204,9 @@ func (p *Process) Kill(ctx context.Context, signal uint32, _ bool) error {
Signal: signal,
Pid: uint32(p.pid),
})
if err != nil {
err = errors.New(grpc.ErrorDesc(err))
}
return err
}