8000 fix(manifest): validate project roots in manifest by darkowlzz · Pull Request #1116 · golang/dep · GitHub
[go: up one dir, main page]

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

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

Merged
darkowlzz merged 5 commits into
golang:masterfrom
darkowlzz:manifest-pr-validate
Sep 10, 2017
Merged

darkowlzz merged 5 commits into
golang:masterfrom
darkowlzz:manifest-pr-validate

Conversation

@darkowlzz
@darkowlzz darkowlzz commented Sep 3, 2017 •
Copy link
Copy Markdown
Collaborator

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

Comment thread 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
Copy Markdown
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}"

@darkowlzz darkowlzz Sep 4, 2017 •
Copy link
Copy Markdown
Collaborator Author

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
Comment thread manifest.go Outdated
projectRoots = append(projectRoots, pr)
}

for _, pr := range projectRoots {
Copy link
Copy Markdown
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.

Comment thread 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
Copy Markdown
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
Copy Markdown
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

@jmank88 jmank88 left a comment
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Concurrency LGTM.

Comment thread manifest.go Outdated
} else if origPR != pr {
errorCh <- fmt.Errorf("the name for %q should be changed to %q", pr, origPR)
}
}(pr)
Copy link
Copy Markdown
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
Copy Markdown
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!

Comment thread manifest.go Outdated
} else if origPR != pr {
errorCh <- fmt.Errorf("the name for %q should be changed to %q", pr, origPR)
}
}
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.com-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.com-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.

@ibrasho ibrasho left a comment
Copy link
Copy Markdown
Collaborator

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.

Comment thread 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")
@ibrasho ibrasho Sep 8, 2017 •
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

s/Following/following/

Comment thread manifest.go
defer wg.Done()
origPR, err := sm.DeduceProjectRoot(string(pr))
if err != nil {
errorCh <- err
Copy link
Copy Markdown
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
Copy Markdown
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 :)

Comment thread manifest_test.go Outdated
name: "valid project root",
manifest: Manifest{
Constraints: map[gps.ProjectRoot]gps.ProjectProperties{
gps.ProjectRoot("github.com/goland/dep"): {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

goland? 😁

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

0