From cf3b72852a0a52d9f47ecc1a79b0664a856cccc5 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Tue, 8 Dec 2015 10:07:55 -0800 Subject: [PATCH] Add log and more context to errors in Create Signed-off-by: Alexander Morozov --- linux/linux.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/linux/linux.go b/linux/linux.go index 8a97b4f..6b4d274 100644 --- a/linux/linux.go +++ b/linux/linux.go @@ -14,6 +14,7 @@ import ( "strings" "syscall" + "github.com/Sirupsen/logrus" "github.com/docker/containerd/runtime" "github.com/opencontainers/runc/libcontainer" "github.com/opencontainers/runc/libcontainer/configs" @@ -355,13 +356,17 @@ func (r *libcontainerRuntime) Create(id, bundlePath string, stdio *runtime.Stdio if err != nil { return nil, err } + logrus.WithFields(logrus.Fields{ + "id": id, + "bundlePath": bundlePath, + }).Debugf("create container") config, err := r.createLibcontainerConfig(id, bundlePath, spec, rspec) if err != nil { return nil, err } container, err := r.factory.Create(id, config) if err != nil { - return nil, err + return nil, fmt.Errorf("create container: %v", err) } process, err := r.newProcess(spec.Process, stdio) if err != nil { @@ -413,14 +418,14 @@ func (r *libcontainerRuntime) newProcess(p specs.Process, stdio *runtime.Stdio) if stdio.Stdout != "" { f, err := os.OpenFile(stdio.Stdout, os.O_CREATE|os.O_WRONLY, 0755) if err != nil { - return nil, err + return nil, fmt.Errorf("open stdout: %v", err) } stdout = f } if stdio.Stderr != "" { f, err := os.OpenFile(stdio.Stderr, os.O_CREATE|os.O_WRONLY, 0755) if err != nil { - return nil, err + return nil, fmt.Errorf("open stderr: %v", err) } stderr = f } @@ -458,10 +463,10 @@ func (r *libcontainerRuntime) loadSpec(cPath, rPath string) (spec *specs.LinuxSp defer rf.Close() if err = json.NewDecoder(cf).Decode(&spec); err != nil { - return spec, rspec, err + return spec, rspec, fmt.Errorf("unmarshal %s: %v", cPath, err) } if err = json.NewDecoder(rf).Decode(&rspec); err != nil { - return spec, rspec, err + return spec, rspec, fmt.Errorf("unmarshal %s: %v", rPath, err) } return spec, rspec, r.checkSpecVersion(spec) }