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

Commit dd59503

Browse files
committed
Warn for no name
Dynamic version constraint error message Only warn for version constraint when it's a constraint field
1 parent 3d3b5e2 commit dd59503

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

manifest.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var (
3939
errRootPruneContainsName = errors.Errorf("%q should not include a name", "prune")
4040
errInvalidRootPruneValue = errors.New("root prune options must be omitted instead of being set to false")
4141
errInvalidPruneProjectName = errors.Errorf("%q in %q must be a string", "name", "prune.project")
42+
errNoName = errors.New("no name provided")
4243
)
4344

4445
// Manifest holds manifest file data and implements gps.RootManifest.
@@ -158,8 +159,10 @@ func validateManifest(s string) ([]error, error) {
158159
warns = append(warns, fmt.Errorf("invalid key %q in %q", key, prop))
159160
}
160161
}
161-
if !ruleProvided && len(props) > 0 {
162-
warns = append(warns, fmt.Errorf("version rule or source should be provided in %q", prop))
162+
if _, ok := props["name"]; !ok {
163+
warns = append(warns, errNoName)
164+
} else if !ruleProvided && prop == "constraint" {
165+
warns = append(warns, fmt.Errorf("branch, version, revision, or source should be provided for %q", props["name"]))
163166
}
164167
}
165168
}

manifest_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func TestValidateManifest(t *testing.T) {
255255
`,
256256
wantWarn: []error{
257257
errInvalidMetadata,
258-
errors.New("version rule or source should be provided in \"constraint\""),
258+
errors.New("branch, version, revision, or source should be provided for \"github.com/foo/bar\""),
259259
},
260260
wantError: nil,
261261
},
@@ -266,7 +266,7 @@ func TestValidateManifest(t *testing.T) {
266266
name = "github.com/foo/bar"
267267
`,
268268
wantWarn: []error{
269-
errors.New("version rule or source should be provided in \"constraint\""),
269+
errors.New("branch, version, revision, or source should be provided for \"github.com/foo/bar\""),
270270
},
271271
wantError: nil,
272272
},
@@ -275,7 +275,9 @@ func TestValidateManifest(t *testing.T) {
275275
tomlString: `
276276
[[constraint]]
277277
`,
278-
wantWarn: []error{},
278+
wantWarn: []error{
279+
errNoName,
280+
},
279281
wantError: nil,
280282
},
281283
{
@@ -300,17 +302,17 @@ func TestValidateManifest(t *testing.T) {
300302
[[override]]
301303
name = "github.com/foo/bar"
302304
`,
303-
wantWarn: []error{
304-
errors.New("version rule or source should be provided in \"override\""),
305-
},
305+
wantWarn: []error{},
306306
wantError: nil,
307307
},
308308
{
309309
name: "empty override",
310310
tomlString: `
311311
[[override]]
312312
`,
313-
wantWarn: []error{},
313+
wantWarn: []error{
314+
errNoName,
315+
},
314316
wantError: nil,
315317
},
316318
{
@@ -344,10 +346,10 @@ func TestValidateManifest(t *testing.T) {
344346
wantWarn: []error{
345347
errors.New("Invalid key \"location\" in \"constraint\""),
346348
errors.New("Invalid key \"link\" in \"constraint\""),
347-
errors.New("version rule or source should be provided in \"constraint\""),
348-
errors.New("Invalid key \"nick\" in \"override\""),
349349
errors.New("metadata in \"constraint\" should be a TOML table"),
350-
errors.New("version rule or source should be provided in \"override\""),
350+
errors.New("branch, version, revision, or source should be provided for \"github.com/foo/bar\""),
351+
errors.New("Invalid key \"nick\" in \"override\""),
352+
errNoName,
351353
},
352354
wantError: nil,
353355
},
@@ -361,7 +363,7 @@ func TestValidateManifest(t *testing.T) {
361363
color = "blue"
362364
`,
363365
wantWarn: []error{
364-
errors.New("version rule or source should be provided in \"constraint\""),
366+
errors.New("branch, version, revision, or source should be provided for \"github.com/foo/bar\""),
365367
},
366368
wantError: nil,
367369
},

0 commit comments

Comments
 (0)