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

cmd/dep: make checkErrors more lenient #997

Merged

Conversation

ibrasho
Copy link
Collaborator

@ibrasho ibrasho commented Aug 12, 2017

What does this do / why do we need it?

checkErrors currently doesn't allow dep ensure to be used in a project that contains any Go files with build errors. This PR update checkErrors to return a warning instead of an error as long as the project contains some compilable Go files.

What should your reviewer look out for in this PR?

Does this make sense?

Do you need help or clarification on anything?

Why did we add that check in the first case?

Which issue(s) does this PR fix?

Fixes #995

@ibrasho ibrasho requested a review from sdboyer August 12, 2017 14:02
@ibrasho ibrasho self-assigned this Aug 12, 2017
@sdboyer
Copy link
Member

sdboyer commented Aug 12, 2017

the basic algoirhtm seems right, but i think it might be better just to keep it simple and encap all the logic in checkErrors(), rather than bleeding some deciisonmaking out to its callers.

if necessary, we can add another param to checkErrors() to afford similar controls.

@ibrasho
Copy link
Collaborator Author

ibrasho commented Aug 13, 2017

Any suggestions? Should I return two values (err, warn error)? Or add a logger as an argument?

@jmank88
Copy link
Collaborator

jmank88 commented Aug 14, 2017

I like returning (warn, err error).

@jmank88
Copy link
Collaborator

jmank88 commented Aug 14, 2017

Or maybe (warn bool, err error)/(fatal bool, err error)?

}

func (e *pkgtreeErrs) Error() string {
var errors []string
Copy link
Collaborator

@jmank88 jmank88 Aug 14, 2017

Choose a reason for hiding this comment

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

nit: could init slice to exact capacity here: errors := make([]string, 0, len(e.errs)) (or only make with a length, and use the index instead of append in the loop)

@sdboyer
Copy link
Member

sdboyer commented Aug 16, 2017

let's go with (fatal bool, err error) - no point in warning if we're also going to fatal.

@ibrasho ibrasho force-pushed the update-checkErrors-to-be-more-lenient branch 2 times, most recently from 754ab11 to 245f2ab Compare August 18, 2017 12:04
@ibrasho
Copy link
Collaborator Author

ibrasho commented Aug 18, 2017

Updated.

return err
} else if ctx.Verbose {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this block only execute if err != nil?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My bad, there should have been another nested if.

ctx.Out.Println(errs)
} else {
ctx.Out.Println(err)
}
Copy link
Collaborator

@jmank88 jmank88 Aug 18, 2017

Choose a reason for hiding this comment

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

Do these two behave differently?

Zooming out a bit and considering both: is this equivalent (or should it be)?

if fatal, err := checkErrors(params.RootPackageTree.Packages); err != nil {
  if fatal {
    return err
  } else if ctx.Verbose {
    ctx.Out.Println(err)
  }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was my original intention. 😁

@ibrasho ibrasho force-pushed the update-checkErrors-to-be-more-lenient branch 3 times, most recently from 95dbb1d to b06f843 Compare August 19, 2017 09:46
@ibrasho
Copy link
Collaborator Author

ibrasho commented Aug 19, 2017

Updated again. 😁

t.Fail()
fatal, err := checkErrors(tc.pkgOrErrMap)
if err == nil && fatal {
t.Fatalf("unexpected fatal flag %T value while err in nil", fatal)
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/in nil/is nil

Also, fatal is always true in this block, so the dynamic formatting is not necessary.

@ibrasho ibrasho force-pushed the update-checkErrors-to-be-more-lenient branch from b06f843 to e0f45d4 Compare August 19, 2017 17:27
@ibrasho
Copy link
Collaborator Author

ibrasho commented Aug 19, 2017

And again. 😛

return true, pkgtreeErrors
}

// If m contained some errors, return a warning with these errors.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: these those errors

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Collaborator

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

LGTM

checkErrors doesn't allow dep ensure to be used in a project that
contains any Go files containing build errors. This commit update
checkErrors to return a warning instead of an error as long as the
project contains some compilable Go files.

Fixes golang#995

Signed-off-by: Ibrahim AshShohail <[email protected]>
@ibrasho ibrasho force-pushed the update-checkErrors-to-be-more-lenient branch from e0f45d4 to b5c378e Compare August 22, 2017 17:13
@ibrasho ibrasho merged commit 1f6d6bb into golang:master Aug 22, 2017
@ibrasho ibrasho deleted the update-checkErrors-to-be-more-lenient branch November 29, 2017 06:18
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.

checkErrors is preventing dep ensure from working within dep
6 participants