@@ -130,7 +130,7 @@ func (v *Validator) CheckAll() error {
130130func JSONSchemaURL (version string ) (url string , err error ) {
131131 ver , err := semver .Parse (version )
132132 if err != nil {
133- return "" , err
133+ return "" , specerror . NewError ( specerror . SpecVersionInSemVer , err , rspec . Version )
134134 }
135135 configRenamedToConfigSchemaVersion , err := semver .Parse ("1.0.0-rc2" ) // config.json became config-schema.json in 1.0.0-rc2
136136 if ver .Compare (configRenamedToConfigSchemaVersion ) == - 1 {
@@ -276,7 +276,12 @@ func (v *Validator) CheckHooks() (errs error) {
276276func (v * Validator ) checkEventHooks (hookType string , hooks []rspec.Hook , hostSpecific bool ) (errs error ) {
277277 for i , hook := range hooks {
278278 if ! osFilepath .IsAbs (v .platform , hook .Path ) {
279- errs = multierror .Append (errs , fmt .Errorf ("hooks.%s[%d].path %v: is not absolute path" , hookType , i , hook .Path ))
279+ errs = multierror .Append (errs ,
280+ specerror .NewError (
281+ specerror .PosixHooksPathAbs ,
282+ fmt .Errorf ("hooks.%s[%d].path %v: is not absolute path" ,
283+ hookType , i , hook .Path ),
284+ rspec .Version ))
280285 }
281286
282287 if hostSpecific {
@@ -309,7 +314,11 @@ func (v *Validator) CheckProcess() (errs error) {
309314
310315 process := v .spec .Process
311316 if ! osFilepath .IsAbs (v .platform , process .Cwd ) {
312- errs = multierror .Append (errs , fmt .Errorf ("cwd %q is not an absolute path" , process .Cwd ))
317+ errs = multierror .Append (errs ,
318+ specerror .NewError (
319+ specerror .ProcCwdAbs ,
320+ fmt .Errorf ("cwd %q is not an absolute path" , process .Cwd ),
321+ rspec .Version ))
313322 }
314323
315324 for _ , env := range process .Env {
@@ -319,7 +328,11 @@ func (v *Validator) CheckProcess() (errs error) {
319328 }
320329
321330 if len (process .Args ) == 0 {
322- errs = multierror .Append (errs , fmt .Errorf ("args must not be empty" ))
331+ errs = multierror .Append (errs ,
332+ specerror .NewError (
333+ specerror .ProcArgsOneEntryRequired ,
334+ fmt .Errorf ("args must not be empty" ),
335+ rspec .Version ))
323336 } else {
324337 if filepath .IsAbs (process .Args [0 ]) {
325338 var rootfsPath string
@@ -432,7 +445,12 @@ func (v *Validator) CheckRlimits() (errs error) {
432445 for index , rlimit := range process .Rlimits {
433446 for i := index + 1 ; i < len (process .Rlimits ); i ++ {
434447 if process .Rlimits [index ].Type == process .Rlimits [i ].Type {
435- errs = multierror .Append (errs , fmt .Errorf ("rlimit can not contain the same type %q" , process .Rlimits [index ].Type ))
448+ errs = multierror .Append (errs ,
449+ specerror .NewError (
450+ specerror .PosixProcRlimitsErrorOnDup ,
451+ fmt .Errorf ("rlimit can not contain the same type %q" ,
452+ process .Rlimits [index ].Type ),
453+ rspec .Version ))
436454 }
437455 }
438456 errs = multierror .Append (errs , v .rlimitValid (rlimit ))
@@ -497,7 +515,13 @@ func (v *Validator) CheckMounts() (errs error) {
497515 errs = multierror .Append (errs , fmt .Errorf ("unsupported mount type %q" , mountA .Type ))
498516 }
499517 if ! osFilepath .IsAbs (v .platform , mountA .Destination ) {
500- errs = multierror .Append (errs , fmt .Errorf ("mounts[%d].destination %q is not absolute" , i , mountA .Destination ))
518+ errs = multierror .Append (errs ,
519+ specerror .NewError (
520+ specerror .MountsDestAbs ,
521+ fmt .Errorf ("mounts[%d].destination %q is not absolute" ,
522+ i ,
523+ mountA .Destination ),
524+ rspec .Version ))
501525 }
502526 for j , mountB := range v .spec .Mounts {
503527 if i == j {
@@ -511,7 +535,12 @@ func (v *Validator) CheckMounts() (errs error) {
511535 }
512536 if nested {
513537 if v .platform == "windows" && i < j {
514- errs = multierror .Append (errs , fmt .Errorf ("on Windows, %v nested within %v is forbidden" , mountB .Destination , mountA .Destination ))
538+ errs = multierror .Append (errs ,
539+ specerror .NewError (
540+ specerror .MountsDestOnWindowsNotNested ,
541+ fmt .Errorf ("on Windows, %v nested within %v is forbidden" ,
542+ mountB .Destination , mountA .Destination ),
543+ rspec .Version ))
515544 }
516545 if i > j {
517546 logrus .Warnf ("%v will be covered by %v" , mountB .Destination , mountA .Destination )
@@ -534,7 +563,11 @@ func (v *Validator) CheckPlatform() (errs error) {
534563
535564 if v .platform == "windows" {
536565 if v .spec .Windows == nil {
537- errs = multierror .Append (errs , errors .New ("'windows' MUST be set when platform is `windows`" ))
566+ errs = multierror .Append (errs ,
567+ specerror .NewError (
568+ specerror .PlatformSpecConfOnWindowsSet ,
569+ fmt .Errorf ("'windows' MUST be set when platform is `windows`" ),
570+ rspec .Version ))
538571 }
539572 }
540573
@@ -705,13 +738,21 @@ func (v *Validator) CheckLinux() (errs error) {
705738
706739 for _ , maskedPath := range v .spec .Linux .MaskedPaths {
707740 if ! strings .HasPrefix (maskedPath , "/" ) {
708- errs = multierror .Append (errs , fmt .Errorf ("maskedPath %v is not an absolute path" , maskedPath ))
741+ errs = multierror .Append (errs ,
742+ specerror .NewError (
743+ specerror .MaskedPathsAbs ,
744+ fmt .Errorf ("maskedPath %v is not an absolute path" , maskedPath ),
745+ rspec .Version ))
709746 }
710747 }
711748
712749 for _ , readonlyPath := range v .spec .Linux .ReadonlyPaths {
713750 if ! strings .HasPrefix (readonlyPath , "/" ) {
714- errs = multierror .Append (errs , fmt .Errorf ("readonlyPath %v is not an absolute path" , readonlyPath ))
751+ errs = multierror .Append (errs ,
752+ specerror .NewError (
753+ specerror .ReadonlyPathsAbs ,
754+ fmt .Errorf ("readonlyPath %v is not an absolute path" , readonlyPath ),
755+ rspec .Version ))
715756 }
716757 }
717758
0 commit comments