From 9ab1f6756b6ecea55aca988ff464bbfff454d0d4 Mon Sep 17 00:00:00 2001 From: Etienne Perot Date: Tue, 31 May 2022 15:44:05 -0700 Subject: [PATCH] runsc: Add more precise error messages in `{container,sandbox}.go`. PiperOrigin-RevId: 452158030 --- runsc/container/container.go | 12 ++++++------ runsc/sandbox/sandbox.go | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/runsc/container/container.go b/runsc/container/container.go index b6d63120b..2c3f94318 100644 --- a/runsc/container/container.go +++ b/runsc/container/container.go @@ -219,7 +219,7 @@ func New(conf *config.Config, args Args) (*Container, error) { // Lock the container metadata file to prevent concurrent creations of // containers with the same id. if err := c.Saver.lockForNew(); err != nil { - return nil, err + return nil, fmt.Errorf("cannot lock container metadata file: %w", err) } defer c.Saver.unlockOrDie() @@ -252,14 +252,14 @@ func New(conf *config.Config, args Args) (*Container, error) { // part of the cgroup from the start (and all their children processes). parentCgroup, subCgroup, err = c.setupCgroupForRoot(conf, args.Spec) if err != nil { - return nil, err + return nil, fmt.Errorf("cannot set up cgroup for root: %w", err) } } c.CompatCgroup = cgroup.CgroupJSON{Cgroup: subCgroup} if err := runInCgroup(parentCgroup, func() error { ioFiles, specFile, err := c.createGoferProcess(args.Spec, conf, args.BundleDir, args.Attached) if err != nil { - return err + return fmt.Errorf("cannot create gofer process: %w", err) } // Start a new sandbox for this container. Any errors after this point @@ -277,7 +277,7 @@ func New(conf *config.Config, args Args) (*Container, error) { } sand, err := sandbox.New(conf, sandArgs) if err != nil { - return err + return fmt.Errorf("cannot create sandbox: %w", err) } c.Sandbox = sand return nil @@ -295,7 +295,7 @@ func New(conf *config.Config, args Args) (*Container, error) { } sb, err := Load(conf.RootDir, fullID, LoadOpts{Exact: true}) if err != nil { - return nil, err + return nil, fmt.Errorf("cannot load sandbox: %w", err) } c.Sandbox = sb.Sandbox @@ -320,7 +320,7 @@ func New(conf *config.Config, args Args) (*Container, error) { } if err := c.Sandbox.CreateSubcontainer(conf, c.ID, tty); err != nil { - return nil, err + return nil, fmt.Errorf("cannot create subcontainer: %w", err) } } c.changeStatus(Created) diff --git a/runsc/sandbox/sandbox.go b/runsc/sandbox/sandbox.go index 3ab04f711..ac52cb834 100644 --- a/runsc/sandbox/sandbox.go +++ b/runsc/sandbox/sandbox.go @@ -202,7 +202,7 @@ func New(conf *config.Config, args *Args) (*Sandbox, error) { } args.SinkFiles, err = initConf.Setup() if err != nil { - return nil, err + return nil, fmt.Errorf("cannot init config: %w", err) } } @@ -219,7 +219,7 @@ func New(conf *config.Config, args *Args) (*Sandbox, error) { // process exits unexpectedly. sandboxSyncFile.Close() if err != nil { - return nil, err + return nil, fmt.Errorf("cannot create sandbox process: %w", err) } // Wait until the sandbox has booted. @@ -237,7 +237,7 @@ func New(conf *config.Config, args *Args) (*Sandbox, error) { return nil, fmt.Errorf("%v: %v", err, permsErr) } } - return nil, err + return nil, fmt.Errorf("cannot read client sync file: %w", err) } c.Release() @@ -623,7 +623,7 @@ func (s *Sandbox) createSandboxProcess(conf *config.Config, args *Args, startSyn specFile, err := specutils.OpenSpec(args.BundleDir) if err != nil { - return err + return fmt.Errorf("cannot open spec file in bundle dir %v: %w", args.BundleDir, err) } donations.DonateAndClose("spec-fd", specFile) @@ -634,7 +634,7 @@ func (s *Sandbox) createSandboxProcess(conf *config.Config, args *Args, startSyn gPlatform, err := platform.Lookup(conf.Platform) if err != nil { - return err + return fmt.Errorf("cannot look up platform: %w", err) } if deviceFile, err := gPlatform.OpenDevice(conf.PlatformDevicePath); err != nil { return fmt.Errorf("opening device file for platform %q: %v", conf.Platform, err)