Skip to content

Commit

Permalink
libct/error.go: rm ConfigError
Browse files Browse the repository at this point in the history
ConfigError was added by commit e918d02, while removing runc own
error system, to preserve a way for a libcontainer user to distinguish
between a configuration error and something else.

The way ConfigError is implemented requires a different type of check
(compared to all other errors defined by error.go). An attempt was made
to rectify this, but the resulting code became even more complicated.

As no one is using this functionality (of differentiating a "bad config"
type of error from other errors), let's just drop the ConfigError type.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Aug 24, 2021
1 parent 6145628 commit 538ba84
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
2 changes: 1 addition & 1 deletion libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (c *linuxContainer) Start(process *Process) error {
c.m.Lock()
defer c.m.Unlock()
if c.config.Cgroups.Resources.SkipDevices {
return &ConfigError{"can't start container with SkipDevices set"}
return errors.New("can't start container with SkipDevices set")
}
if process.Init {
if err := c.createExecFifo(); err != nil {
Expand Down
8 changes: 0 additions & 8 deletions libcontainer/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,3 @@ var (
ErrNotRunning = errors.New("container not running")
ErrNotPaused = errors.New("container not paused")
)

type ConfigError struct {
details string
}

func (e *ConfigError) Error() string {
return "invalid configuration: " + e.details
}
6 changes: 3 additions & 3 deletions libcontainer/factory_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ type LinuxFactory struct {

func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, error) {
if l.Root == "" {
return nil, &ConfigError{"invalid root"}
return nil, errors.New("root not set")
}
if err := l.validateID(id); err != nil {
return nil, err
}
if err := l.Validator.Validate(config); err != nil {
return nil, &ConfigError{err.Error()}
return nil, err
}
containerRoot, err := securejoin.SecureJoin(l.Root, id)
if err != nil {
Expand Down Expand Up @@ -294,7 +294,7 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err

func (l *LinuxFactory) Load(id string) (Container, error) {
if l.Root == "" {
return nil, &ConfigError{"invalid root"}
return nil, errors.New("root not set")
}
// when load, we need to check id is valid or not.
if err := l.validateID(id); err != nil {
Expand Down

0 comments on commit 538ba84

Please sign in to comment.