Skip to content

Commit

Permalink
fix: remove showing app name twice in errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mitar committed Jul 21, 2023
1 parent a9be85c commit 5a2e694
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,19 @@ func (c *Context) Validate() error { // nolint: gocyclo

case *Application:
value = node.Target
desc = node.Name
desc = ""

case *Node:
value = node.Target
desc = node.Path()
}
if validate := isValidatable(value); validate != nil {
if err := validate.Validate(); err != nil {
return fmt.Errorf("%s: %w", desc, err)
if desc != "" {
return fmt.Errorf("%s: %w", desc, err)
} else {
return err
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion kong_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ func TestValidateApp(t *testing.T) {
cli := validateCli{}
p := mustNew(t, &cli)
_, err := p.Parse([]string{})
assert.EqualError(t, err, "test: app error")
assert.EqualError(t, err, "app error")
}

func TestValidateCmd(t *testing.T) {
Expand Down

0 comments on commit 5a2e694

Please sign in to comment.