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
specerror: Pull runtime-spec-specific error handling into its own package
With 8f4d367 (error: Pull the RFC 2119 error representation into its
own package, 2017-07-28, #437), I'd created a package that was
completely independent of runtime-spec. As I pointed out in that
commit message, this made it possible for image-tools and other
projects to reuse the generic RFC 2119 handling (which they care
about) without involving the runtime-spec-specific error enumeration
and such (which they don't care about).
In 2520212 (add stretchr/testify/assert pkgs; use rfc code in bundle
validation, 2017-08-29, #451), some runtime-spec-specific
functionality leaked into the error package. I'd recommended keeping
configuration and runtime requirements separate [1], because you're
unlikely to be testing both of those at once. But Liang wanted them
collected [2,3]. And the NewError and FindError utilities would be
the same regardless of target, so that's a good argument for keeping
them together. This commit moves the runtime-spec-specific
functionality into a new package where both config and runtime
validators can share it, but where it won't pollute the generic RFC
2119 error package.
I've also changed NewError to take an error argument instead of a
string message, because creating an error from a string is easy
(e.g. with fmt.Errorf(...)), and using an error allows you to preserve
any additional structured information from a system error (e.g. as
returned by GetMounts).
[1]: #451 (comment)
[2]: #451 (comment)
[3]: #451 (comment)
Signed-off-by: W. Trevor King <[email protected]>
rerr.NewError(rerr.ArtifactsInSingleDir, fmt.Sprintf("root.path is %q, but it MUST be a child of %q", v.spec.Root.Path, absBundlePath), rspec.Version))
170
+
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))
171
171
}
172
172
173
173
ifv.platform=="windows" {
174
174
ifv.spec.Root.Readonly {
175
175
errs=multierror.Append(errs,
176
-
rerr.NewError(rerr.ReadonlyOnWindows, "root.readonly field MUST be omitted or false when target platform is windows", rspec.Version))
176
+
specerror.NewError(specerror.ReadonlyOnWindows, fmt.Errorf("root.readonly field MUST be omitted or false when target platform is windows"), rspec.Version))
rerr.NewError(rerr.SpecVersion, fmt.Sprintf("%q is not valid SemVer: %s", version, err.Error()), rspec.Version))
191
+
specerror.NewError(specerror.SpecVersion, fmt.Errorf("%q is not valid SemVer: %s", version, err.Error()), rspec.Version))
192
192
}
193
193
ifversion!=rspec.Version {
194
194
errs=multierror.Append(errs, fmt.Errorf("validate currently only handles version %s, but the supplied configuration targets %s", rspec.Version, version))
0 commit comments