Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specerror: Pull runtime-spec-specific error handling into its own package #455

Merged
merged 2 commits into from
Sep 1, 2017

Conversation

wking
Copy link
Contributor

@wking wking commented Aug 30, 2017

With #437, I'd created a package that was completely independent of runtime-spec. As I pointed out in that PR, 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 #451, some runtime-spec-specific functionality leaked into the error package. I'd recommended keeping configuration and runtime requirements separate, because you're unlikely to be testing both of those at once. But @liangchenye wanted them collected. 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 specerror 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).

The second commit in this PR cleans up some of the generic RFC 2119 package's godocs.

@wking wking force-pushed the specerror-package branch from 9343391 to c3a8d2c Compare August 30, 2017 20:56
{"", false, rerr.NewError(rerr.CreateWithID, "'Create' MUST generate an error if the ID is not provided", rspecs.Version)},
{containerID, true, rerr.NewError(rerr.CreateNewContainer, "'Create' MUST create a new container", rspecs.Version)},
{containerID, false, rerr.NewError(rerr.CreateWithUniqueID, "'Create' MUST generate an error if the ID provided is not unique", rspecs.Version)},
{"", false, specerror.NewError(specerror.CreateWithID, "'Create' MUST generate an error if the ID is not provided", rspecs.Version)},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with new format of NewError(), but it seems you leave behind here three place. I wonder why there is no error when compiling.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validation_test.go will not run in our CI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with new format of NewError(), but it seems you leave behind here three place.

Oops. Thanks. Fixed with c3a8d2c7e95c6f.

@liangchenye
Copy link
Member

I'm ok with this change. Only the test case issue need to be fixed. @wking

wking added 2 commits August 31, 2017 17:22
…kage

With 8f4d367 (error: Pull the RFC 2119 error representation into its
own package, 2017-07-28, opencontainers#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, opencontainers#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]: opencontainers#451 (comment)
[2]: opencontainers#451 (comment)
[3]: opencontainers#451 (comment)

Signed-off-by: W. Trevor King <[email protected]>
Remove OCI references from the comments, because this is a generic RFC
2119 package and has nothing OCI-specific.  Also document the Error
properties.

Signed-off-by: W. Trevor King <[email protected]>
@wking wking force-pushed the specerror-package branch from 7e95c6f to f9152f1 Compare September 1, 2017 00:22
@wking
Copy link
Contributor Author

wking commented Sep 1, 2017

I fixed a go fmt … error with 7e95c6ff9152f1.

@Mashimiao
Copy link

Mashimiao commented Sep 1, 2017

LGTM

Approved with PullApprove

1 similar comment
@zhouhao3
Copy link

zhouhao3 commented Sep 1, 2017

LGTM

Approved with PullApprove

@liangchenye liangchenye merged commit d6e5f82 into opencontainers:master Sep 1, 2017
@wking wking deleted the specerror-package branch September 6, 2017 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants