Skip to content
This repository was archived by the owner on Aug 14, 2020. It is now read-only.

schema/types: don't panic validating incomplete isolators #633

Merged
merged 1 commit into from
Jun 27, 2016

Conversation

lucab
Copy link
Contributor

@lucab lucab commented Jun 23, 2016

Even though Isolator instances should be constructed via
unmarshaling, library users may still construct one directly
with a nil value.
This commit fixes the validator to handle this error gracefully
instead of panicing.

@lucab
Copy link
Contributor Author

lucab commented Jun 23, 2016

It turns out rkt has some tests doing exactly what godoc says not to do. I'm going to fix those tests, but this makes validation a bit more graceful. I'm not sure if there is an easy way to forbid this at all without making the type hierarchy even more complex.

@lucab lucab mentioned this pull request Jun 23, 2016
@euank
Copy link
Contributor

euank commented Jun 23, 2016

LGTM. I have no problem with making it fail more gracefully in this case of user-error.

@jonboulle
Copy link
Contributor

Ideally ValueRaw would not be exported at all, but we're hamstrung there by Go's json marshalling rules

@@ -24,6 +24,7 @@ var (
isolatorMap map[ACIdentifier]IsolatorValueConstructor

ErrIncompatibleIsolator = errors.New("isolators set contains incompatible types")
ErrInvalidIsolator = errors.New("invalid isolator")
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a docstring for this error? hinting that it might be thrown if an Isolator is constructed incorrectly for example

Copy link
Contributor Author

@lucab lucab Jun 24, 2016

Choose a reason for hiding this comment

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

Yup, the one above too? In general I haven't seen lot of docstring around error constants, but I will be happy to have more.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah - in this case in particular I think it helps because as a consumer of the package it's unclear why I'd ever encounter this (it's unfortunate that we allow them to even get into this situation)

@lucab lucab force-pushed the to-upstream/isolator-value branch from 9845f2f to 0ae6774 Compare June 24, 2016 13:34
@lucab
Copy link
Contributor Author

lucab commented Jun 24, 2016

Amended.

ErrIncompatibleIsolator = errors.New("isolators set contains incompatible types")
// ErrInvalidIsolator is thrown upon validation failures due to improper
// or partially constructed Isolator instances (ie. not constructed via unmarshaling)
Copy link
Contributor

Choose a reason for hiding this comment

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

The ie is wrong (since valid isolators can be constructed from the New* functions).

Also errors are returned, not thrown.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uhm, right.

Even though Isolator instances should be constructed via
unmarshaling, library users may still construct one directly
with a nil value.
This commit fixes the validator to handle this error gracefully
instead of panicing.
@lucab lucab force-pushed the to-upstream/isolator-value branch from 0ae6774 to d3cde07 Compare June 24, 2016 14:16
@jonboulle jonboulle merged commit 208ad62 into appc:master Jun 27, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants