@@ -130,7 +130,7 @@ func (v *Validator) CheckAll() error {
130
130
func JSONSchemaURL (version string ) (url string , err error ) {
131
131
ver , err := semver .Parse (version )
132
132
if err != nil {
133
- return "" , err
133
+ return "" , specerror . NewError ( specerror . SpecVersionInSemVer , err , rspec . Version )
134
134
}
135
135
configRenamedToConfigSchemaVersion , err := semver .Parse ("1.0.0-rc2" ) // config.json became config-schema.json in 1.0.0-rc2
136
136
if ver .Compare (configRenamedToConfigSchemaVersion ) == - 1 {
@@ -276,7 +276,12 @@ func (v *Validator) CheckHooks() (errs error) {
276
276
func (v * Validator ) checkEventHooks (hookType string , hooks []rspec.Hook , hostSpecific bool ) (errs error ) {
277
277
for i , hook := range hooks {
278
278
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 ))
280
285
}
281
286
282
287
if hostSpecific {
@@ -309,7 +314,11 @@ func (v *Validator) CheckProcess() (errs error) {
309
314
310
315
process := v .spec .Process
311
316
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 ))
313
322
}
314
323
315
324
for _ , env := range process .Env {
@@ -319,7 +328,11 @@ func (v *Validator) CheckProcess() (errs error) {
319
328
}
320
329
321
330
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 ))
323
336
} else {
324
337
if filepath .IsAbs (process .Args [0 ]) {
325
338
var rootfsPath string
@@ -432,7 +445,12 @@ func (v *Validator) CheckRlimits() (errs error) {
432
445
for index , rlimit := range process .Rlimits {
433
446
for i := index + 1 ; i < len (process .Rlimits ); i ++ {
434
447
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 ))
436
454
}
437
455
}
438
456
errs = multierror .Append (errs , v .rlimitValid (rlimit ))
@@ -497,7 +515,13 @@ func (v *Validator) CheckMounts() (errs error) {
497
515
errs = multierror .Append (errs , fmt .Errorf ("unsupported mount type %q" , mountA .Type ))
498
516
}
499
517
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 ))
501
525
}
502
526
for j , mountB := range v .spec .Mounts {
503
527
if i == j {
@@ -511,7 +535,12 @@ func (v *Validator) CheckMounts() (errs error) {
511
535
}
512
536
if nested {
513
537
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 ))
515
544
}
516
545
if i > j {
517
546
logrus .Warnf ("%v will be covered by %v" , mountB .Destination , mountA .Destination )
@@ -534,7 +563,11 @@ func (v *Validator) CheckPlatform() (errs error) {
534
563
535
564
if v .platform == "windows" {
536
565
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 ))
538
571
}
539
572
}
540
573
@@ -705,13 +738,21 @@ func (v *Validator) CheckLinux() (errs error) {
705
738
706
739
for _ , maskedPath := range v .spec .Linux .MaskedPaths {
707
740
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 ))
709
746
}
710
747
}
711
748
712
749
for _ , readonlyPath := range v .spec .Linux .ReadonlyPaths {
713
750
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 ))
715
756
}
716
757
}
717
758
0 commit comments