runsc: Add more precise error messages in {container,sandbox}.go.

PiperOrigin-RevId: 452158030
This commit is contained in:
Etienne Perot
2022-05-31 15:46:40 -07:00
committed by gVisor bot
parent 3ec7b4b614
commit 9ab1f6756b
2 changed files with 11 additions and 11 deletions
+6 -6
View File
@@ -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)
+5 -5
View File
@@ -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)