Skip to content

Commit

Permalink
adjust newapp/newbuild error messages (arg classification vs. actual …
Browse files Browse the repository at this point in the history
…processing)
  • Loading branch information
gabemontero committed Jan 26, 2018
1 parent cf406ea commit 533e96a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pkg/generate/app/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ type ErrNoMatch struct {

func (e ErrNoMatch) Error() string {
if len(e.Qualifier) != 0 {
return fmt.Sprintf("no match for %q: %s", e.Value, e.Qualifier)
return fmt.Sprintf("unable to locate resource for %q: %s", e.Value, e.Qualifier)
}
return fmt.Sprintf("no match for %q", e.Value)
return fmt.Sprintf("unable to locate resource for %q", e.Value)
}

// Suggestion is the usage error message returned when no match is found.
Expand Down
18 changes: 7 additions & 11 deletions pkg/oc/cli/cmd/newapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,24 +714,20 @@ func handleError(err error, baseName, commandName, commandPath string, config *n
transformError(err, baseName, commandName, commandPath, groups)
}
buf := &bytes.Buffer{}
if len(config.ArgumentClassificationErrors) > 0 {
fmt.Fprintf(buf, "Errors occurred while determining argument types:\n")
for _, classErr := range config.ArgumentClassificationErrors {
fmt.Fprintf(buf, fmt.Sprintf("\n%s: %v\n", classErr.Key, classErr.Value))
}
fmt.Fprint(buf, "\n")
// this print serves as a header for the printing of the errorGroups, but
// only print it if we precede with classification errors, to help distinguish
// between the two
fmt.Fprintln(buf, "Errors occurred during resource creation:")
}
for _, group := range groups {
fmt.Fprint(buf, kcmdutil.MultipleErrors("error: ", group.errs))
if len(group.suggestion) > 0 {
fmt.Fprintln(buf)
}
fmt.Fprint(buf, group.suggestion)
}
if len(config.ArgumentClassificationErrors) > 0 && len(groups) > 0 {
fmt.Fprintf(buf, "\nFor further assistance, %s classification of the argument types resulted in the following:\n", commandName)
for _, classErr := range config.ArgumentClassificationErrors {
fmt.Fprintf(buf, fmt.Sprintf("\n%s: %v\n", classErr.Key, classErr.Value))
}
fmt.Fprintf(buf, fmt.Sprintf("\n%s", config.ArgumentClassificationWinner))
}
return fmt.Errorf(buf.String())
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/oc/generate/app/cmd/newapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type AppConfig struct {
OriginNamespace string

ArgumentClassificationErrors []ArgumentClassificationError
ArgumentClassificationWinner string
}

type ArgumentClassificationError struct {
Expand Down Expand Up @@ -312,6 +313,7 @@ func (c *AppConfig) tryToAddTemplateArguments(s string) bool {
// AddArguments converts command line arguments into the appropriate bucket based on what they look like
func (c *AppConfig) AddArguments(args []string) []string {
unknown := []string{}
winnerFmt := "The argument %s passed the %s classification tests"
c.ArgumentClassificationErrors = []ArgumentClassificationError{}
for _, s := range args {
if len(s) == 0 {
Expand All @@ -320,9 +322,14 @@ func (c *AppConfig) AddArguments(args []string) []string {

switch {
case c.tryToAddEnvironmentArguments(s):
c.ArgumentClassificationWinner = fmt.Sprintf(winnerFmt, s, "environment")
case c.tryToAddSourceArguments(s):
case c.tryToAddComponentArguments(s):
c.ArgumentClassificationWinner = fmt.Sprintf(winnerFmt, s, "source")
case c.tryToAddTemplateArguments(s):
c.ArgumentClassificationWinner = fmt.Sprintf(winnerFmt, s, "template")
case c.tryToAddComponentArguments(s):
// NOTE, component argument classification currently is the most lenient, so we save it for the end
c.ArgumentClassificationWinner = fmt.Sprintf(winnerFmt, s, "component")
default:
glog.V(2).Infof("treating %s as unknown\n", s)
unknown = append(unknown, s)
Expand Down
6 changes: 3 additions & 3 deletions test/cmd/newapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ os::cmd::expect_success_and_text 'oc new-app --dry-run --docker-image=mysql' 'Th
os::cmd::expect_success_and_text 'oc new-app --dry-run --docker-image=mysql' "WARNING: Image \"mysql\" runs as the 'root' user"

# verify multiple errors are displayed together, a nested error is returned, and that the usage message is displayed
os::cmd::expect_failure_and_text 'oc new-app --dry-run __template_fail __templatefile_fail' 'error: no match for "__template_fail"'
os::cmd::expect_failure_and_text 'oc new-app --dry-run __template_fail __templatefile_fail' 'error: no match for "__templatefile_fail"'
os::cmd::expect_failure_and_text 'oc new-app --dry-run __template_fail __templatefile_fail' 'error: unable to locate resource for "__template_fail"'
os::cmd::expect_failure_and_text 'oc new-app --dry-run __template_fail __templatefile_fail' 'error: unable to locate resource for "__templatefile_fail"'
os::cmd::expect_failure_and_text 'oc new-app --dry-run __template_fail __templatefile_fail' 'error: unable to find the specified template file'
os::cmd::expect_failure_and_text 'oc new-app --dry-run __template_fail __templatefile_fail' "The 'oc new-app' command will match arguments"

Expand Down Expand Up @@ -448,7 +448,7 @@ os::cmd::expect_success_and_text 'oc new-app -f test/testdata/circular.yaml' 'sh
os::cmd::expect_success_and_not_text 'oc new-app -f test/testdata/bc-from-imagestreamimage.json --dry-run' 'Unable to follow reference type'

# do not allow use of non-existent image (should fail)
os::cmd::expect_failure_and_text 'oc new-app openshift/bogusimage https://github.com/openshift/ruby-hello-world.git -o yaml' "no match for"
os::cmd::expect_failure_and_text 'oc new-app openshift/bogusimage https://github.com/openshift/ruby-hello-world.git -o yaml' "unable to locate resource for"
# allow use of non-existent image (should succeed)
os::cmd::expect_success 'oc new-app openshift/bogusimage https://github.com/openshift/ruby-hello-world.git -o yaml --allow-missing-images'

Expand Down
2 changes: 1 addition & 1 deletion test/integration/newapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestNewAppResolve(t *testing.T) {
},
},
})},
expectedErr: `no match for "mysql:invalid`,
expectedErr: `unable to locate resource for "mysql:invalid`,
},
{
name: "Successful mysql builder",
Expand Down

0 comments on commit 533e96a

Please sign in to comment.