Skip to content

Commit 20af327

Browse files
author
Ma Shimiao
authored
Merge pull request #502 from q384566678/rfc-fix
translate RFC errors
2 parents df01456 + 90ace62 commit 20af327

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

Diff for: cmd/runtimetest/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ func validateLinuxDevices(spec *rspec.Spec) error {
368368
}
369369
fStat, ok := fi.Sys().(*syscall.Stat_t)
370370
if !ok {
371-
return fmt.Errorf("cannot determine state for device %s", device.Path)
371+
return specerror.NewError(specerror.DevicesAvailable, fmt.Errorf("cannot determine state for device %s", device.Path), rspec.Version)
372372
}
373373
var devType string
374374
switch fStat.Mode & syscall.S_IFMT {

Diff for: validate/validate.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ func (v *Validator) CheckLinux() (errs error) {
604604
tmpItem := nsTypeList[ns.Type]
605605
tmpItem.num = tmpItem.num + 1
606606
if tmpItem.num > 1 {
607-
errs = multierror.Append(errs, fmt.Errorf("duplicated namespace %q", ns.Type))
607+
errs = multierror.Append(errs, specerror.NewError(specerror.NSErrorOnDup, fmt.Errorf("duplicated namespace %q", ns.Type), rspec.Version))
608608
}
609609

610610
if len(ns.Path) == 0 {
@@ -663,7 +663,8 @@ func (v *Validator) CheckLinux() (errs error) {
663663
} else {
664664
fStat, ok := fi.Sys().(*syscall.Stat_t)
665665
if !ok {
666-
errs = multierror.Append(errs, fmt.Errorf("cannot determine state for device %s", device.Path))
666+
errs = multierror.Append(errs, specerror.NewError(specerror.DevicesAvailable,
667+
fmt.Errorf("cannot determine state for device %s", device.Path), rspec.Version))
667668
continue
668669
}
669670
var devType string
@@ -678,35 +679,40 @@ func (v *Validator) CheckLinux() (errs error) {
678679
devType = "unmatched"
679680
}
680681
if devType != device.Type || (devType == "c" && device.Type == "u") {
681-
errs = multierror.Append(errs, fmt.Errorf("unmatched %s already exists in filesystem", device.Path))
682+
errs = multierror.Append(errs, specerror.NewError(specerror.DevicesFileNotMatch,
683+
fmt.Errorf("unmatched %s already exists in filesystem", device.Path), rspec.Version))
682684
continue
683685
}
684686
if devType != "p" {
685687
dev := fStat.Rdev
686688
major := (dev >> 8) & 0xfff
687689
minor := (dev & 0xff) | ((dev >> 12) & 0xfff00)
688690
if int64(major) != device.Major || int64(minor) != device.Minor {
689-
errs = multierror.Append(errs, fmt.Errorf("unmatched %s already exists in filesystem", device.Path))
691+
errs = multierror.Append(errs, specerror.NewError(specerror.DevicesFileNotMatch,
692+
fmt.Errorf("unmatched %s already exists in filesystem", device.Path), rspec.Version))
690693
continue
691694
}
692695
}
693696
if device.FileMode != nil {
694697
expectedPerm := *device.FileMode & os.ModePerm
695698
actualPerm := fi.Mode() & os.ModePerm
696699
if expectedPerm != actualPerm {
697-
errs = multierror.Append(errs, fmt.Errorf("unmatched %s already exists in filesystem", device.Path))
700+
errs = multierror.Append(errs, specerror.NewError(specerror.DevicesFileNotMatch,
701+
fmt.Errorf("unmatched %s already exists in filesystem", device.Path), rspec.Version))
698702
continue
699703
}
700704
}
701705
if device.UID != nil {
702706
if *device.UID != fStat.Uid {
703-
errs = multierror.Append(errs, fmt.Errorf("unmatched %s already exists in filesystem", device.Path))
707+
errs = multierror.Append(errs, specerror.NewError(specerror.DevicesFileNotMatch,
708+
fmt.Errorf("unmatched %s already exists in filesystem", device.Path), rspec.Version))
704709
continue
705710
}
706711
}
707712
if device.GID != nil {
708713
if *device.GID != fStat.Gid {
709-
errs = multierror.Append(errs, fmt.Errorf("unmatched %s already exists in filesystem", device.Path))
714+
errs = multierror.Append(errs, specerror.NewError(specerror.DevicesFileNotMatch,
715+
fmt.Errorf("unmatched %s already exists in filesystem", device.Path), rspec.Version))
710716
continue
711717
}
712718
}

0 commit comments

Comments
 (0)