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 that not-exist and pattern error return different results #109488

Merged
merged 1 commit into from Apr 14, 2022

Conversation

soltysh
Copy link
Contributor

@soltysh soltysh commented Apr 14, 2022

What type of PR is this?

/kind bug
/kind regression

What this PR does / why we need it:

This fixes the regression introduced in #102265 which doesn't differentiate between non-existent path and wrong syntax for glob.

Special notes for your reviewer:

/assign @liggitt @eddiezane

Does this PR introduce a user-facing change?

NONE

@k8s-ci-robot k8s-ci-robot added the release-note-none Denotes a PR that doesn't merit a release note. label Apr 14, 2022
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. kind/regression Categorizes issue or PR as related to a regression from a prior release. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 14, 2022
@soltysh
Copy link
Contributor Author

soltysh commented Apr 14, 2022

/sig cli
/triage accepted
/priority backlog

@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Apr 14, 2022
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 14, 2022
@soltysh
Copy link
Contributor Author

soltysh commented Apr 14, 2022

/milestone v1.24

@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Apr 14, 2022
@eddiezane
Copy link
Member

Thank you! Nice catch.

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: eddiezane, soltysh

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

@@ -707,6 +707,37 @@ func TestFilePatternBuilder(t *testing.T) {
}
}

func TestErrorFilePatternBuilder(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the table tests, but aren't the two new cases the exact same situations as the ones in the tests you modified above? Maybe I'm missing something, but it seems to me the main difference is the final if !strings.Contains(err.Error(), pathPattern) { assertion, which could be added to the table tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other are much more granular, these are more higher level and are in a single place, I was considering dropping the other two, but TestFilePatternBuilderWhenPatternYieldsNoResult covers 2 cases actually, since it's both glob and a non-existent directory. Where as the non-existent file in my case is just about the file, so I've decided to leave it as us.

@@ -1213,11 +1213,12 @@ func expandIfFilePattern(pattern string) ([]string, error) {
if _, err := os.Stat(pattern); os.IsNotExist(err) {
matches, err := filepath.Glob(pattern)
if err == nil && len(matches) == 0 {
return nil, fmt.Errorf("no match")
return nil, fmt.Errorf("the path %q does not exist", pattern)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this to remain the exact same as the error returned when a literal path is used but the file does not exist, i.e. the error we had before? This seems to be the right message, but I'm thinking we should future-proof it by creating a single error message source for this and the other location (L419 maybe?). Or for the same effect, perhaps we could allow this case to fall through to the original check (the way it looks like the err == filepath.ErrBadPattern is doing, undesirably, on master right now)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same message was my explicit intention, I'll open a followup to squash both into a single place for future proofing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@KnVerey as promised fixes in #109504

@k8s-ci-robot k8s-ci-robot merged commit e207aab into kubernetes:master Apr 14, 2022
@soltysh soltysh deleted the fix_globmatch branch April 15, 2022 10:34
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. kind/bug Categorizes issue or PR as related to a bug. kind/regression Categorizes issue or PR as related to a regression from a prior release. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note-none Denotes a PR that doesn't merit a release note. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants