Skip to content

Commit bd75bc2

Browse files
authored
Merge pull request opencontainers#3176 from kolyshkin/rm-config-error-alt
libct/error.go: rm ConfigError (alt)
2 parents bde65de + 538ba84 commit bd75bc2

File tree

4 files changed

+10
-21
lines changed

4 files changed

+10
-21
lines changed

libcontainer/configs/validate/validator.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (v *ConfigValidator) Validate(config *configs.Config) error {
5252
}
5353
for _, c := range warns {
5454
if err := c(config); err != nil {
55-
logrus.WithError(err).Warnf("invalid configuration")
55+
logrus.WithError(err).Warn("invalid configuration")
5656
}
5757
}
5858
return nil
@@ -62,20 +62,17 @@ func (v *ConfigValidator) Validate(config *configs.Config) error {
6262
// to the container's root filesystem.
6363
func (v *ConfigValidator) rootfs(config *configs.Config) error {
6464
if _, err := os.Stat(config.Rootfs); err != nil {
65-
if os.IsNotExist(err) {
66-
return fmt.Errorf("rootfs (%s) does not exist", config.Rootfs)
67-
}
68-
return err
65+
return fmt.Errorf("invalid rootfs: %w", err)
6966
}
7067
cleaned, err := filepath.Abs(config.Rootfs)
7168
if err != nil {
72-
return err
69+
return fmt.Errorf("invalid rootfs: %w", err)
7370
}
7471
if cleaned, err = filepath.EvalSymlinks(cleaned); err != nil {
75-
return err
72+
return fmt.Errorf("invalid rootfs: %w", err)
7673
}
7774
if filepath.Clean(config.Rootfs) != cleaned {
78-
return fmt.Errorf("%s is not an absolute path or is a symlink", config.Rootfs)
75+
return errors.New("invalid rootfs: not an absolute path, or a symlink")
7976
}
8077
return nil
8178
}
@@ -176,7 +173,7 @@ func (v *ConfigValidator) sysctl(config *configs.Config) error {
176173
hostnet, hostnetErr = isHostNetNS(path)
177174
})
178175
if hostnetErr != nil {
179-
return hostnetErr
176+
return fmt.Errorf("invalid netns path: %w", hostnetErr)
180177
}
181178
if hostnet {
182179
return fmt.Errorf("sysctl %q not allowed in host network namespace", s)

libcontainer/container_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (c *linuxContainer) Start(process *Process) error {
229229
c.m.Lock()
230230
defer c.m.Unlock()
231231
if c.config.Cgroups.Resources.SkipDevices {
232-
return &ConfigError{"can't start container with SkipDevices set"}
232+
return errors.New("can't start container with SkipDevices set")
233233
}
234234
if process.Init {
235235
if err := c.createExecFifo(); err != nil {

libcontainer/error.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,3 @@ var (
1111
ErrNotRunning = errors.New("container not running")
1212
ErrNotPaused = errors.New("container not paused")
1313
)
14-
15-
type ConfigError struct {
16-
details string
17-
}
18-
19-
func (e *ConfigError) Error() string {
20-
return "invalid configuration: " + e.details
21-
}

libcontainer/factory_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@ type LinuxFactory struct {
249249

250250
func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, error) {
251251
if l.Root == "" {
252-
return nil, &ConfigError{"invalid root"}
252+
return nil, errors.New("root not set")
253253
}
254254
if err := l.validateID(id); err != nil {
255255
return nil, err
256256
}
257257
if err := l.Validator.Validate(config); err != nil {
258-
return nil, &ConfigError{err.Error()}
258+
return nil, err
259259
}
260260
containerRoot, err := securejoin.SecureJoin(l.Root, id)
261261
if err != nil {
@@ -292,7 +292,7 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err
292292

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

0 commit comments

Comments
 (0)