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

Print error message when no matches are found by --filter or --regex flag #125

Merged
merged 1 commit into from
Oct 1, 2017

Conversation

ericstoekl
Copy link
Contributor

Print error message when no matches are found by --filter or --regex flag

Signed-off-by: Eric Stoekl ems5311@gmail.com

Description

This change is to return an error message when all functions are filtered out by the --filter or --regex option. The current error message is "No functions found in YAML, check --filter/--regex".

Motivation and Context

This will help users figure out what is wrong with their command if they expect functions to be deployed, and nothing happens.

How Has This Been Tested?

Tests were upgraded to accommodate this change and check for this error to be properly thrown when --filter and --regex remove all functions.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@open-derek
Copy link

open-derek bot commented Sep 26, 2017

Thank you for your contribution. I've just checked and your commit doesn't appear to be signed-off.
That's something we need before your Pull Request can be merged. Please see our contributing guide.

@open-derek open-derek bot added the no-dco label Sep 26, 2017
@ericstoekl
Copy link
Contributor Author

Just added some extra test functionality, to test that when we expect an error message was returned, to verify that it is the correct error message.

@@ -66,7 +66,6 @@ func ParseYAMLData(fileData []byte, regex string, filter string) (*Services, err
if regexExists {
match, err = regexp.MatchString(regex, function.Name)
if err != nil {
fmt.Printf("Invalid regex passed to --regex option\n")
Copy link
Member

Choose a reason for hiding this comment

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

This message was deleted?

Copy link
Contributor Author

@ericstoekl ericstoekl Sep 26, 2017

Choose a reason for hiding this comment

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

There is already an error thrown by the regex parser when the regex is invalid, which gets printed out by each command which calls ParseYAMLFile() by its following error checking block:

if err != nil {
    log.Fataln(err.Error())
    return
}

The line that log.Fataln(err) prints is error parsing regexp: if it's a regex error, so I figured this printf is redundant. Also, for testing, I wanted to confirm the error message, and only have one line print out makes that easier.

Copy link
Member

Choose a reason for hiding this comment

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

As long as you bubble up the error.

@alexellis
Copy link
Member

Very good improvement to the UX here @ericstoekl

@alexellis
Copy link
Member

Can you include the expected messages for given error scenarios below?

@ericstoekl
Copy link
Contributor Author

Expected errors so far:

  1. No matches found for --filter or --regex parameter: No functions matching --filter/--regex were found in the YAML file
  2. Invalid regex used: error parsing regexp: <details about how to fix regex>

For example, if I use the command faas-cli build -f samples.yml --regex [, I get the message:

error parsing regexp: missing closing ]: `[`

These are the only two errors I've encountered so far related to --filter and --regex.

@alexellis
Copy link
Member

Great. Can you now squash your commits or at least sign all of them?

git reset HEAD~2
git add .
git commit -s -m "COMMIT MESSAGE"
git push .... --force

searchTerm: "node",
functions: []string{"nodejs-echo"},
file: TestData_1,
expectError: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could get rid of the expectedErrorMsg and change expectError to a string, use len(test.expectError) > 0 for the conditional - avoids having the redundant variable since you're always checking for the message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks John, will update this evening.

strkeys,
test.functions,
)
if test.expectError {
Copy link
Contributor

Choose a reason for hiding this comment

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

See earlier comment if len(test.expectError) > 0 {

…flag

Improve tests for --filter and --regex

Signed-off-by: Eric Stoekl <ems5311@gmail.com>
@ericstoekl
Copy link
Contributor Author

Addressed the suggestions from @johnmccabe , and squashed the commits

@alexellis
Copy link
Member

LGTM

@alexellis alexellis merged commit fc1d186 into openfaas:master Oct 1, 2017
@alexellis alexellis moved this from In review to Done in #TeamServerless Oct 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants