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

Commit

Permalink
Merge pull request #633 from lucab/to-upstream/isolator-value
Browse files Browse the repository at this point in the history
schema/types: don't panic validating incomplete isolators
  • Loading branch information
jonboulle authored Jun 27, 2016
2 parents 24d784c + d3cde07 commit 208ad62
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions schema/types/isolator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ import (
var (
isolatorMap map[ACIdentifier]IsolatorValueConstructor

// ErrIncompatibleIsolator is returned whenever an Isolators set contains
// conflicting IsolatorValue instances
ErrIncompatibleIsolator = errors.New("isolators set contains incompatible types")
// ErrInvalidIsolator is returned upon validation failures due to improper
// or partially constructed Isolator instances (eg. from incomplete direct construction)
ErrInvalidIsolator = errors.New("invalid isolator")
)

func init() {
Expand All @@ -49,15 +54,19 @@ type Isolators []Isolator
func (isolators Isolators) assertValid() error {
typesMap := make(map[ACIdentifier]bool)
for _, i := range isolators {
if err := i.Value().AssertValid(); err != nil {
v := i.Value()
if v == nil {
return ErrInvalidIsolator
}
if err := v.AssertValid(); err != nil {
return err
}
if _, ok := typesMap[i.Name]; ok {
if !i.Value().multipleAllowed() {
if !v.multipleAllowed() {
return fmt.Errorf(`isolators set contains too many instances of type %s"`, i.Name)
}
}
for _, c := range i.Value().Conflicts() {
for _, c := range v.Conflicts() {
if _, found := typesMap[c]; found {
return ErrIncompatibleIsolator
}
Expand Down

0 comments on commit 208ad62

Please sign in to comment.