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

Commit fc2d241

Browse files
committed
dep: conver some errors to a variable
Signed-off-by: Ibrahim AshShohail <[email protected]>
1 parent 7ed9049 commit fc2d241

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

manifest.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@ const ManifestName = "Gopkg.toml"
2424

2525
// Errors
2626
var (
27-
errInvalidConstraint = errors.Errorf("%q must be a TOML array of tables", "constraint")
28-
errInvalidOverride = errors.Errorf("%q must be a TOML array of tables", "override")
29-
errInvalidRequired = errors.Errorf("%q must be a TOML list of strings", "required")
30-
errInvalidIgnored = errors.Errorf("%q must be a TOML list of strings", "ignored")
31-
errInvalidPrune = errors.Errorf("%q must be a TOML table of booleans", "prune")
32-
33-
errInvalidProjectRoot = errors.New("ProjectRoot name validation failed")
34-
errInvalidPruneValue = errors.New("prune options values must be booleans")
27+
errInvalidConstraint = errors.Errorf("%q must be a TOML array of tables", "constraint")
28+
errInvalidOverride = errors.Errorf("%q must be a TOML array of tables", "override")
29+
errInvalidRequired = errors.Errorf("%q must be a TOML list of strings", "required")
30+
errInvalidIgnored = errors.Errorf("%q must be a TOML list of strings", "ignored")
31+
errInvalidPrune = errors.Errorf("%q must be a TOML table of booleans", "prune")
3532
errInvalidPruneProject = errors.Errorf("%q must be a TOML array of tables", "prune.project")
36-
errPruneSubProject = errors.New("prune projects should not contain sub projects")
33+
errInvalidMetadata = errors.New("metadata should be a TOML table")
3734

35+
errInvalidProjectRoot = errors.New("ProjectRoot name validation failed")
36+
37+
errInvalidPruneValue = errors.New("prune options values must be booleans")
38+
errPruneSubProject = errors.New("prune projects should not contain sub projects")
39+
40+
errRootPruneContainsName = errors.Errorf("%q should not include a name", "prune")
3841
errInvalidRootPruneValue = errors.New("root prune options must be omitted instead of being set to false")
3942
errInvalidPruneProjectName = errors.Errorf("%q in %q must be a string", "name", "prune.project")
4043
)
@@ -115,7 +118,7 @@ func validateManifest(s string) ([]error, error) {
115118
case "metadata":
116119
// Check if metadata is of Map type
117120
if reflect.TypeOf(val).Kind() != reflect.Map {
118-
warns = append(warns, errors.New("metadata should be a TOML table"))
121+
warns = append(warns, errInvalidMetadata)
119122
}
120123
case "constraint", "override":
121124
valid := true
@@ -215,7 +218,7 @@ func validatePruneOptions(val interface{}, root bool) (warns []error, err error)
215218
}
216219
case "name":
217220
if root {
218-
warns = append(warns, errors.Errorf("%q should not include a name", "prune"))
221+
warns = append(warns, errRootPruneContainsName)
219222
} else if _, ok := value.(string); !ok {
220223
return warns, errInvalidPruneProjectName
221224
}

manifest_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ func TestValidateManifest(t *testing.T) {
253253
[[constraint]]
254254
name = "github.com/foo/bar"
255255
`,
256-
wantWarn: []error{errors.New("metadata should be a TOML table")},
256+
wantWarn: []error{
257+
errInvalidMetadata,
258+
},
257259
wantError: nil,
258260
},
259261
{
@@ -402,7 +404,7 @@ func TestValidateManifest(t *testing.T) {
402404
name = "github.com/golang/dep"
403405
`,
404406
wantWarn: []error{
405-
fmt.Errorf("%q should not include a name", "prune"),
407+
errRootPruneContainsName,
406408
},
407409
wantError: nil,
408410
},

0 commit comments

Comments
 (0)