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

Commit

Permalink
dep: conver some errors to a variable
Browse files Browse the repository at this point in the history
Signed-off-by: Ibrahim AshShohail <ibra.sho@gmail.com>
  • Loading branch information
ibrasho committed Nov 17, 2017
1 parent 7ed9049 commit fc2d241
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
25 changes: 14 additions & 11 deletions manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ const ManifestName = "Gopkg.toml"

// Errors
var (
errInvalidConstraint = errors.Errorf("%q must be a TOML array of tables", "constraint")
errInvalidOverride = errors.Errorf("%q must be a TOML array of tables", "override")
errInvalidRequired = errors.Errorf("%q must be a TOML list of strings", "required")
errInvalidIgnored = errors.Errorf("%q must be a TOML list of strings", "ignored")
errInvalidPrune = errors.Errorf("%q must be a TOML table of booleans", "prune")

errInvalidProjectRoot = errors.New("ProjectRoot name validation failed")
errInvalidPruneValue = errors.New("prune options values must be booleans")
errInvalidConstraint = errors.Errorf("%q must be a TOML array of tables", "constraint")
errInvalidOverride = errors.Errorf("%q must be a TOML array of tables", "override")
errInvalidRequired = errors.Errorf("%q must be a TOML list of strings", "required")
errInvalidIgnored = errors.Errorf("%q must be a TOML list of strings", "ignored")
errInvalidPrune = errors.Errorf("%q must be a TOML table of booleans", "prune")
errInvalidPruneProject = errors.Errorf("%q must be a TOML array of tables", "prune.project")
errPruneSubProject = errors.New("prune projects should not contain sub projects")
errInvalidMetadata = errors.New("metadata should be a TOML table")

errInvalidProjectRoot = errors.New("ProjectRoot name validation failed")

errInvalidPruneValue = errors.New("prune options values must be booleans")
errPruneSubProject = errors.New("prune projects should not contain sub projects")

errRootPruneContainsName = errors.Errorf("%q should not include a name", "prune")
errInvalidRootPruneValue = errors.New("root prune options must be omitted instead of being set to false")
errInvalidPruneProjectName = errors.Errorf("%q in %q must be a string", "name", "prune.project")
)
Expand Down Expand Up @@ -115,7 +118,7 @@ func validateManifest(s string) ([]error, error) {
case "metadata":
// Check if metadata is of Map type
if reflect.TypeOf(val).Kind() != reflect.Map {
warns = append(warns, errors.New("metadata should be a TOML table"))
warns = append(warns, errInvalidMetadata)
}
case "constraint", "override":
valid := true
Expand Down Expand Up @@ -215,7 +218,7 @@ func validatePruneOptions(val interface{}, root bool) (warns []error, err error)
}
case "name":
if root {
warns = append(warns, errors.Errorf("%q should not include a name", "prune"))
warns = append(warns, errRootPruneContainsName)
} else if _, ok := value.(string); !ok {
return warns, errInvalidPruneProjectName
}
Expand Down
6 changes: 4 additions & 2 deletions manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ func TestValidateManifest(t *testing.T) {
[[constraint]]
name = "github.com/foo/bar"
`,
wantWarn: []error{errors.New("metadata should be a TOML table")},
wantWarn: []error{
errInvalidMetadata,
},
wantError: nil,
},
{
Expand Down Expand Up @@ -402,7 +404,7 @@ func TestValidateManifest(t *testing.T) {
name = "github.com/golang/dep"
`,
wantWarn: []error{
fmt.Errorf("%q should not include a name", "prune"),
errRootPruneContainsName,
},
wantError: nil,
},
Expand Down

0 comments on commit fc2d241

Please sign in to comment.