You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use a slightly more idiomatic approach, and collect errors before
joining them. This prevents deeply nested error trees.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
specerror.NewError(specerror.RootPathOnWindowsGUID, fmt.Errorf("root.path is %q, but it MUST be a volume GUID path when target platform is windows", v.spec.Root.Path), rspec.Version))
197
+
errs=append(errs, specerror.NewError(specerror.RootPathOnWindowsGUID, fmt.Errorf("root.path is %q, but it MUST be a volume GUID path when target platform is windows", v.spec.Root.Path), rspec.Version))
198
198
}
199
199
200
200
ifv.spec.Root.Readonly {
201
-
errs=errors.Join(errs,
202
-
specerror.NewError(specerror.RootReadonlyOnWindowsFalse, fmt.Errorf("root.readonly field MUST be omitted or false when target platform is windows"), rspec.Version))
201
+
errs=append(errs, specerror.NewError(specerror.RootReadonlyOnWindowsFalse, fmt.Errorf("root.readonly field MUST be omitted or false when target platform is windows"), rspec.Version))
203
202
}
204
203
205
-
return
204
+
returnerrors.Join(errs...)
206
205
}
207
206
208
207
absBundlePath, err:=filepath.Abs(v.bundlePath)
209
208
iferr!=nil {
210
-
errs=errors.Join(errs, fmt.Errorf("unable to convert %q to an absolute path", v.bundlePath))
211
-
return
209
+
returnfmt.Errorf("unable to convert %q to an absolute path", v.bundlePath)
212
210
}
213
211
214
212
iffilepath.Base(v.spec.Root.Path) !="rootfs" {
215
-
errs=errors.Join(errs,
216
-
specerror.NewError(specerror.RootPathOnPosixConvention, fmt.Errorf("path name should be the conventional 'rootfs'"), rspec.Version))
213
+
errs=append(errs, specerror.NewError(specerror.RootPathOnPosixConvention, fmt.Errorf("path name should be the conventional 'rootfs'"), rspec.Version))
specerror.NewError(specerror.ArtifactsInSingleDir, fmt.Errorf("root.path is %q, but it MUST be a child of %q", v.spec.Root.Path, absBundlePath), rspec.Version))
238
+
errs=append(errs, specerror.NewError(specerror.ArtifactsInSingleDir, fmt.Errorf("root.path is %q, but it MUST be a child of %q", v.spec.Root.Path, absBundlePath), rspec.Version))
246
239
}
247
240
248
-
return
241
+
returnerrors.Join(errs...)
249
242
}
250
243
251
244
// CheckSemVer checks v.spec.Version
252
-
func (v*Validator) CheckSemVer() (errserror) {
245
+
func (v*Validator) CheckSemVer() error {
253
246
logrus.Debugf("check semver")
254
247
255
248
version:=v.spec.Version
256
249
_, err:=semver.Parse(version)
257
250
iferr!=nil {
258
-
errs=errors.Join(errs,
259
-
specerror.NewError(specerror.SpecVersionInSemVer, fmt.Errorf("%q is not valid SemVer: %s", version, err.Error()), rspec.Version))
251
+
returnspecerror.NewError(specerror.SpecVersionInSemVer, fmt.Errorf("%q is not valid SemVer: %s", version, err.Error()), rspec.Version)
260
252
}
261
253
ifversion!=rspec.Version {
262
-
errs=errors.Join(errs, fmt.Errorf("validate currently only handles version %s, but the supplied configuration targets %s", rspec.Version, version))
254
+
returnfmt.Errorf("validate currently only handles version %s, but the supplied configuration targets %s", rspec.Version, version)
263
255
}
264
256
265
-
return
257
+
returnnil
266
258
}
267
259
268
260
// CheckHooks check v.spec.Hooks
269
-
func (v*Validator) CheckHooks() (errserror) {
261
+
func (v*Validator) CheckHooks() error {
270
262
logrus.Debugf("check hooks")
271
263
272
264
ifv.platform!="linux"&&v.platform!="solaris" {
273
-
errs=errors.Join(errs, fmt.Errorf("For %q platform, the configuration structure does not support hooks", v.platform))
274
-
return
265
+
returnfmt.Errorf("for %q platform, the configuration structure does not support hooks", v.platform)
fmt.Errorf("hooks.%s[%d].path %v: is not absolute path",
293
-
hookType, i, hook.Path),
294
-
rspec.Version))
289
+
errs=append(errs, specerror.NewError(specerror.PosixHooksPathAbs, fmt.Errorf("hooks.%s[%d].path %v: is not absolute path", hookType, i, hook.Path), rspec.Version))
0 commit comments