-
Notifications
You must be signed in to change notification settings - Fork 1k
fix(manifest): validate project roots in manifest #1116
Conversation
manifest.go
Outdated
return errors.Wrapf(err, "could not deduce project root for %s", pr) | ||
} | ||
if origPR != pr { | ||
c.Err.Printf("dep: WARNING: name %q in Gopkg.toml should be project root", pr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would help if the warning printed out the current name in the manifest and what it should be changed to, e.g.
"... the name for {origPR} in Gopkg.toml should be changed to {pr}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, they need not struggle to figure out what's a project root.
34e1de4
to
9a78083
Compare
manifest.go
Outdated
projectRoots = append(projectRoots, pr) | ||
} | ||
|
||
for _, pr := range projectRoots { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's do these concurrently, otherwise any that require http requests for vanity URLs will end up being serialized.
manifest.go
Outdated
return errors.Wrapf(err, "could not deduce project root for %s", pr) | ||
} | ||
if origPR != pr { | ||
c.Err.Printf("dep: WARNING: the name for %q in Gopkg.toml should be changed to %q", pr, origPR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we doing the dep:
prefix anywhere else? i don't recall. i don't think we are.
in any case, though, per your question in the original PR, i think we want to make this a case where we straight up fail, not just warn. there's nothing valid about these, at all, and we should immediately fail out if we encounter them.
9a78083
to
793785b
Compare
First time writing concurrent go code. Please suggest improvements 😊 This is how the errors are shown:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concurrency LGTM.
manifest.go
Outdated
} else if origPR != pr { | ||
errorCh <- fmt.Errorf("the name for %q should be changed to %q", pr, origPR) | ||
} | ||
}(pr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you define this function ahead of time, then you can launch the go routines from the two separate loops over the original slices, and avoid building the projectRoots
slice and looping over them again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great idea 😃 Thanks!
manifest.go
Outdated
} else if origPR != pr { | ||
errorCh <- fmt.Errorf("the name for %q should be changed to %q", pr, origPR) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this works, but I actually meant you could define a variable to hold the closure which you were already using, rather than invoking it in place. Then the function doesn't have to expand to include those 3 extra arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah! first class functions 😊 Haven't used them in that way much. Anyway, now I know how to use waitGroup
with an external function 😀
Changing to hold the function in a variable.
Thanks again!
2fbfda9
to
07ef084
Compare
Travis failure in osx:
Restarting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, LGTM with minor nits.
manifest.go
Outdated
var valErr error | ||
if len(errorCh) > 0 { | ||
valErr = errInvalidProjectRoot | ||
c.Err.Printf("The Following issues were found in Gopkg.toml:\n\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Following/following/
defer wg.Done() | ||
origPR, err := sm.DeduceProjectRoot(string(pr)) | ||
if err != nil { | ||
errorCh <- err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe prefix the pr just in case the error message is not clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the error messages is returned with PR in it already
✗ github.com/go-yaml is not a valid path for a source on github.com
So, it's fine :)
manifest_test.go
Outdated
name: "valid project root", | ||
manifest: Manifest{ | ||
Constraints: map[gps.ProjectRoot]gps.ProjectProperties{ | ||
gps.ProjectRoot("github.com/goland/dep"): { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goland
? 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I keep doing this a lot. 😂 goland
Validating ProjectRoot(s) require source manager, which is created after loading the project. Hence, ProjectRoot validation can't be done in existing validateManifest. This change adds `ValidateProjectRoots()` which validates only the Constraint and Override names to be valid ProjectRoot. Warnings are issued at stderr when invalid ProjectRoot is found in manifest. `ensure` and `status` call `ValidateProjectRoots()` expecitly.
07ef084
to
ddc0326
Compare
ddc0326
to
fa811f2
Compare
Validating ProjectRoot(s) require source manager, which is created after
loading the project. Hence, ProjectRoot validation can't be done in
existing validateManifest.
This change adds
ValidateProjectRoots()
which validates only the Constraintand Override names to be valid ProjectRoot. Warnings are issued at stderr when
invalid ProjectRoot is found in manifest.
ensure
andstatus
callValidateProjectRoots()
expecitly.What does this do / why do we need it?
Validates ProjectRoots in manifest.
What should your reviewer look out for in this PR?
The warning and error messages.
Do you need help or clarification on anything?
Should we warn or just error out when an invalid ProjectRoot is found?
Which issue(s) does this PR fix?
fixes #984