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

fix(manifest): validate project roots in manifest #1116

Merged
merged 5 commits into from
Sep 10, 2017

Conversation

darkowlzz
Copy link
Collaborator

@darkowlzz darkowlzz commented Sep 3, 2017

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.

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

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)
Copy link
Collaborator

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}"

Copy link
Collaborator Author

@darkowlzz darkowlzz Sep 4, 2017

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.

manifest.go Outdated
projectRoots = append(projectRoots, pr)
}

for _, pr := range projectRoots {
Copy link
Member

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)
Copy link
Member

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.

@darkowlzz
Copy link
Collaborator Author

First time writing concurrent go code. Please suggest improvements 😊

This is how the errors are shown:

$ dep status
The Following issues were found in Gopkg.toml:

  ✗ github.com/go-yaml is not a valid path for a source on github.com
  ✗ the name for "github.com/Masterminds/vcs/foo" should be changed to "github.com/Masterminds/vcs"

ProjectRoot name validation failed

Copy link
Collaborator

@jmank88 jmank88 left a 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)
Copy link
Collaborator

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.

Copy link
Collaborator Author

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)
}
}
Copy link
Collaborator

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.

Copy link
Collaborator Author

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!

@darkowlzz
Copy link
Collaborator Author

Travis failure in osx:

$ go test -race ./...

ok  	github.com/golang/dep	6.118s

ok  	github.com/golang/dep/cmd/dep	110.191s

?   	github.com/golang/dep/hack/licenseok	[no test files]

ok  	github.com/golang/dep/internal/feedback	1.081s

ok  	github.com/golang/dep/internal/fs	1.146s

--- FAIL: TestMultiFetchThreadsafe (17.64s)

    --- FAIL: TestMultiFetchThreadsafe/second (0.10s)

        --- FAIL: TestMultiFetchThreadsafe/second/sync:1:github.com/sdboyer/gpkt (1.16s)

        	manager_test.go:577: https://github.com/sdboyer/gpkt does not exist in the local cache and fetching failed: unable to get repository: Cloning into '/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/smcache192671536/sources/https---git.luolix.top-sdboyer-gpkt'...

        		fatal: remote-curl: fetch attempted without a local repo

        		: command failed: [git clone --recursive -v --progress https://github.com/sdboyer/gpkt /var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/smcache192671536/sources/https---git.luolix.top-sdboyer-gpkt]: exit status 128

Signal received: waiting for 1 ops to complete...

FAIL

FAIL	github.com/golang/dep/internal/gps	92.879s

ok  	github.com/golang/dep/internal/gps/paths	1.031s

ok  	github.com/golang/dep/internal/gps/pkgtree	1.178s

?   	github.com/golang/dep/internal/gps/testdata_digest/github.com/alice/match	[no test files]

?   	github.com/golang/dep/internal/gps/testdata_digest/github.com/alice/mismatch	[no test files]

?   	github.com/golang/dep/internal/gps/testdata_digest/github.com/alice/notInLock	[no test files]

?   	github.com/golang/dep/internal/gps/testdata_digest/github.com/bob/emptyDigest	[no test files]

?   	github.com/golang/dep/internal/gps/testdata_digest/github.com/bob/match	[no test files]

?   	github.com/golang/dep/internal/gps/testdata_digest/launchpad.net/match	[no test files]

?   	github.com/golang/dep/internal/test	[no test files]

?   	github.com/golang/dep/internal/test/integration	[no test files]

The command "go test -race ./..." exited with 1.

Done. Your build exited with 1.

Restarting.

Copy link
Collaborator

@ibrasho ibrasho left a 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")
Copy link
Collaborator

@ibrasho ibrasho Sep 8, 2017

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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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"): {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goland? 😁

Copy link
Collaborator Author

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.
@darkowlzz darkowlzz merged commit 28fb6b0 into golang:master Sep 10, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dep ensure pulls malformed subpackage
6 participants