Format errors better for CLI (#552)
* Start making errors easier to read for Table based CLI UI. * Add TODO about reporting "update_mask" related errors.
This commit is contained in:
1 parent
d6c6aea179
commit
6c6fb7a4d0
22 files changed
+90
-63
No files matched your search
@@ -279,8 +279,8 @@ func (c *Command) Run(args []string) int {
|
||||
plural = "accounts"
|
||||
}
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -204,8 +204,8 @@ func (c *PasswordCommand) Run(args []string) int {
|
||||
|
||||
plural := "password-type account"
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -127,8 +127,8 @@ func (c *PasswordCommand) Run(args []string) int {
|
||||
"password": c.flagPassword,
|
||||
})
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing authentication: %s", err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing authentication: %s", base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to perform authentication: %s", err.Error()))
|
||||
|
||||
@@ -175,8 +175,8 @@ func (c *Command) Run(args []string) int {
|
||||
plural = "auth methods"
|
||||
}
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -194,8 +194,8 @@ func (c *PasswordCommand) Run(args []string) int {
|
||||
|
||||
plural := "password-type auth-method"
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -112,8 +112,8 @@ func (c *Command) Run(args []string) int {
|
||||
plural = "auth tokens"
|
||||
}
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -193,8 +193,8 @@ func (c *Command) Run(args []string) int {
|
||||
plural = "groups"
|
||||
}
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -175,8 +175,8 @@ func (c *Command) Run(args []string) int {
|
||||
plural = "host catalogs"
|
||||
}
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -150,8 +150,8 @@ func (c *StaticCommand) Run(args []string) int {
|
||||
|
||||
plural := "static-type host-catalog"
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -173,8 +173,8 @@ func (c *Command) Run(args []string) int {
|
||||
plural = "hosts"
|
||||
}
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -178,8 +178,8 @@ func (c *StaticCommand) Run(args []string) int {
|
||||
|
||||
plural := "static-type host"
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -265,8 +265,8 @@ func (c *Command) Run(args []string) int {
|
||||
plural = "host sets"
|
||||
}
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -148,8 +148,8 @@ func (c *StaticCommand) Run(args []string) int {
|
||||
|
||||
plural := "static-type host-set"
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -456,8 +456,8 @@ func (c *Command) Run(args []string) (retCode int) {
|
||||
|
||||
sar, err := targetClient.AuthorizeSession(c.Context, c.flagTargetId, opts...)
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing authorize-session against target: %s", err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing authorize-session against target: %s", base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to authorize a session against target: %s", err.Error()))
|
||||
|
||||
@@ -244,8 +244,8 @@ func (c *Command) Run(args []string) int {
|
||||
plural = "roles"
|
||||
}
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -171,8 +171,8 @@ func (c *Command) Run(args []string) int {
|
||||
plural = "scopes"
|
||||
}
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -130,8 +130,8 @@ func (c *Command) Run(args []string) int {
|
||||
plural = "sessions"
|
||||
}
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -294,8 +294,8 @@ func (c *Command) Run(args []string) int {
|
||||
plural = "a session against target"
|
||||
}
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -222,8 +222,8 @@ func (c *TcpCommand) Run(args []string) int {
|
||||
|
||||
plural := "tcp-type target"
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
@@ -193,8 +193,8 @@ func (c *Command) Run(args []string) int {
|
||||
plural = "users"
|
||||
}
|
||||
if err != nil {
|
||||
if api.AsServerError(err) != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, err.Error()))
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
c.UI.Error(fmt.Sprintf("Error from controller when performing %s on %s: %s", c.Func, plural, base.PrintApiError(apiErr)))
|
||||
return 1
|
||||
}
|
||||
c.UI.Error(fmt.Sprintf("Error trying to %s %s: %s", c.Func, plural, err.Error()))
|
||||
|
||||
Reference in new issue
Block a user