From 9d69d85bc13d4f0956a39951b5cd6777f938cffd Mon Sep 17 00:00:00 2001 From: Ian Lewis Date: Thu, 1 Nov 2018 17:39:20 -0700 Subject: [PATCH] Make error messages a bit more user friendly. Updated error messages so that it doesn't print full Go struct representations when running a new container in a sandbox. For example, this occurs frequently when commands are not found when doing a 'kubectl exec'. PiperOrigin-RevId: 219729141 Change-Id: Ic3a7bc84cd7b2167f495d48a1da241d621d3ca09 --- pkg/sentry/control/proc.go | 11 +++++++++++ runsc/boot/loader.go | 4 ++-- runsc/sandbox/sandbox.go | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/sentry/control/proc.go b/pkg/sentry/control/proc.go index b6ac2f312..923399fb2 100644 --- a/pkg/sentry/control/proc.go +++ b/pkg/sentry/control/proc.go @@ -19,6 +19,7 @@ import ( "encoding/json" "fmt" "sort" + "strings" "text/tabwriter" "time" @@ -88,6 +89,16 @@ type ExecArgs struct { ContainerID string } +// String prints the arguments as a string. +func (args ExecArgs) String() string { + a := make([]string, len(args.Argv)) + copy(a, args.Argv) + if args.Filename != "" { + a[0] = args.Filename + } + return strings.Join(a, " ") +} + // Exec runs a new task. func (proc *Proc) Exec(args *ExecArgs, waitStatus *uint32) error { newTG, _, _, err := proc.execAsync(args) diff --git a/runsc/boot/loader.go b/runsc/boot/loader.go index abb347835..380fa3fbf 100644 --- a/runsc/boot/loader.go +++ b/runsc/boot/loader.go @@ -618,7 +618,7 @@ func (l *Loader) executeAsync(args *control.ExecArgs) (kernel.ThreadID, error) { ep, ok := l.processes[rootKey] l.mu.Unlock() if !ok { - return 0, fmt.Errorf("cannot exec in container %q: no such container", args.ContainerID) + return 0, fmt.Errorf("no such container: %q", args.ContainerID) } ep.tg.Leader().WithMuLocked(func(t *kernel.Task) { args.Root = t.FSContext().RootDirectory() @@ -631,7 +631,7 @@ func (l *Loader) executeAsync(args *control.ExecArgs) (kernel.ThreadID, error) { proc := control.Proc{Kernel: l.k} tg, tgid, ttyFile, err := control.ExecAsync(&proc, args) if err != nil { - return 0, fmt.Errorf("error executing: %+v: %v", args, err) + return 0, err } // Insert the process into processes so that we can wait on it diff --git a/runsc/sandbox/sandbox.go b/runsc/sandbox/sandbox.go index df235c5e9..9421bd63e 100644 --- a/runsc/sandbox/sandbox.go +++ b/runsc/sandbox/sandbox.go @@ -229,7 +229,7 @@ func (s *Sandbox) Execute(args *control.ExecArgs) (int32, error) { // Send a message to the sandbox control server to start the container. var pid int32 if err := conn.Call(boot.ContainerExecuteAsync, args, &pid); err != nil { - return 0, fmt.Errorf("error executing in sandbox: %v", err) + return 0, fmt.Errorf("error executing command %q in sandbox: %v", args, err) } return pid, nil }