Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure 'not exist' errors wrap os.ErrNotExist #3982

Merged
merged 3 commits into from
Jun 11, 2021

Conversation

campoy
Copy link
Contributor

@campoy campoy commented Jun 10, 2021

Updates #3873

This PR ensures that all "not exist" types return an error for which errors.Is(err, os.ErrNotExist) is true.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 10, 2021
@k8s-ci-robot
Copy link
Contributor

Hi @campoy. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 10, 2021
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 10, 2021
@natasha41575
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 10, 2021
Copy link
Contributor

@natasha41575 natasha41575 left a comment

Choose a reason for hiding this comment

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

The presubmit check is failing because the api module is missing a go.sum entry, you can see the error output here: https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_kustomize/3982/kustomize-presubmit-master/1403066536456884224

Besides that, the change looks okay to me, though could you clarify what benefit this provides?

@k8s-ci-robot
Copy link
Contributor

@campoy: This PR has multiple commits, and the default merge method is: merge.
You can request commits to be squashed using the label: tide/merge-method-squash

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@campoy
Copy link
Contributor Author

campoy commented Jun 10, 2021

Of course, yes.

I'm working on #3873 and I want to ensure that the behavior of the different implementations of FileSystem behave the same way.

Right now, some of the checks that I would do are failing because the error returned when opening a non existent file on FsOnDisk do wrap os.ErrNotExist, but not FsInMemory.

I also just sent an updated go.sum.

@campoy
Copy link
Contributor Author

campoy commented Jun 10, 2021

Regarding the multiple commits, I'm totally fine squashing them but I don't think I can request that myself.

Should I squash it manually on my end?

@natasha41575 natasha41575 added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jun 10, 2021
Copy link
Contributor

@natasha41575 natasha41575 left a comment

Choose a reason for hiding this comment

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

Minor nits

@@ -236,7 +236,7 @@ func (n *fsNode) CleanedAbs(path string) (ConfirmedDir, string, error) {
return "", "", errors.Wrap(err, "unable to clean")
}
if node == nil {
return "", "", fmt.Errorf("'%s' doesn't exist", path)
return "", "", fmt.Errorf("'%s' doesn't exist: %w", path, os.ErrNotExist)
Copy link
Contributor

@natasha41575 natasha41575 Jun 10, 2021

Choose a reason for hiding this comment

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

This seems a bit redundant. Maybe just fmt.Errorf("'%s': %w", path, osErr.NotExist) so that the output reads 'filename': file does not exist

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -351,6 +352,9 @@ func (n *fsNode) IsDir(path string) bool {

// ReadDir implements FileSystem.
func (n *fsNode) ReadDir(path string) ([]string, error) {
if !n.Exists(path) {
return nil, fmt.Errorf("%s does not exist: %w", path, os.ErrNotExist)
Copy link
Contributor

@natasha41575 natasha41575 Jun 10, 2021

Choose a reason for hiding this comment

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

same comment here as above, and let's put single quotes around '%s'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@natasha41575
Copy link
Contributor

note: You can run make prow-presubmit-check locally to run this check. (The helm tests fail on my machine so I usually comment them out.)

@campoy
Copy link
Contributor Author

campoy commented Jun 11, 2021

After having to fix too many tests, I realized that there was a way to avoid having to change anything on the client's side by using a custom error type!

@natasha41575
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 11, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: campoy, natasha41575

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 11, 2021
@k8s-ci-robot k8s-ci-robot merged commit 199802a into kubernetes-sigs:master Jun 11, 2021
@campoy campoy deleted the fix-not-exists branch June 11, 2021 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants