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

Guard against errs in stripVendor WalkFunc #1026

Merged
merged 5 commits into from
Aug 17, 2017

Conversation

sdboyer
Copy link
Member

@sdboyer sdboyer commented Aug 17, 2017

What does this do / why do we need it?

defends against errors/panics in the filepath.WalkFunc we use to strip out vendor directories, gps.stripVendor()

What should your reviewer look out for in this PR?

Which issue(s) does this PR fix?

fixes #1022

err := filepath.Walk(to, stripVendor)
if err != nil {
errCh <- errors.Wrapf(err, "failed to strip vendor from %s", p.Ident().ProjectRoot)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now the errCh buffer is too small since each routine could send 2 errors. Does that even make sense? Or should the first error terminate the goroutine? (maybe defer the wg.Done() so we can return from there)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes good call

@sdboyer
Copy link
Member Author

sdboyer commented Aug 17, 2017

of course there are windows errors 😠

@@ -10,6 +10,10 @@ import (
)

func stripVendor(path string, info os.FileInfo, err error) error {
if err != nil && err != filepath.SkipDir {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think filepath.SkipDir is ever passed again to the walkFn.

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, that was actually the problem, i think - see my comment on main thread.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Have you actually seen filepath.SkipDir here? Wouldn't that be a sever std lib bug?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's possible that i'm cargo culting this, lemme see

@sdboyer
Copy link
Member Author

sdboyer commented Aug 17, 2017

oh, there was an actual bug here - we were removing the vendor dir, but not telling the walker to skip as a dir to then subsequently traverse.

@sdboyer
Copy link
Member Author

sdboyer commented Aug 17, 2017

this windows problem is...bizarre, i don't understand why that's happening. pinging my trusty @ChrisHines 😄 - do you know if filepath.Walk() treats filepath.SkipDir any differently on windows?

@sdboyer
Copy link
Member Author

sdboyer commented Aug 17, 2017

why, windows. WHY. 😠

@@ -10,6 +10,10 @@ import (
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should there be a //+build windows at the top of this file?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, the _windows.go file suffix does the same thing.

@ChrisHines
Copy link
Contributor

I don't understand all the context here, but I notice that this PR updates the strip_vendor.go file, but not the strip_vendor_windows.go file. Does a similar change need to be made for the Windows implementation of stripVendor?

@ChrisHines
Copy link
Contributor

@sdboyer You're most recent commit does not affect the Windows impl of stripVendor so your commit message there doesn't make sense to me.

@sdboyer
Copy link
Member Author

sdboyer commented Aug 17, 2017

@ChrisHines 🤦‍♂️ 🤦‍♂️ 🤦‍♂️ i am so sorry to have summoned you for this boneheaded mistake. i'm looking forward to my vacation. thank you!

@sdboyer
Copy link
Member Author

sdboyer commented Aug 17, 2017

ok, somebody else approve and merge when it seems OK to them

@@ -12,10 +12,6 @@ import (
)

func stripVendor(path string, info os.FileInfo, err error) error {
if err != nil && err != filepath.SkipDir {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we still need this check, but only the if err != nil { part.

Copy link
Collaborator

@ibrasho ibrasho Aug 17, 2017

Choose a reason for hiding this comment

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

Because the path passed causes os.Lstat to return an error somehow, then walkFn will be passed nil for info and the error. Jumping to the code below will cause the panic again.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, finally looked at the filepath.Walk() implementation - lstat(), or readDirNames(). ok 😄

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.

LGTM

@sdboyer sdboyer merged commit 6ca8a48 into golang:master Aug 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid memory address or nil pointer dereference when running dep ensure
5 participants