From 6c8235d031e937c75cb4318740512ff4dec7c1a0 Mon Sep 17 00:00:00 2001 From: Ben Schumacher Date: Fri, 28 Mar 2025 09:30:41 +0100 Subject: [PATCH] Fix missing errors in mmctl output (#30567) --- server/cmd/mmctl/commands/command.go | 4 ++-- server/cmd/mmctl/commands/command_test.go | 4 ++-- server/cmd/mmctl/commands/config.go | 6 +++--- server/cmd/mmctl/commands/post.go | 2 +- server/cmd/mmctl/commands/user.go | 2 +- server/cmd/mmctl/commands/user_e2e_test.go | 4 ++-- server/cmd/mmctl/commands/user_test.go | 8 ++++---- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/server/cmd/mmctl/commands/command.go b/server/cmd/mmctl/commands/command.go index 351be19533..ef16db5b91 100644 --- a/server/cmd/mmctl/commands/command.go +++ b/server/cmd/mmctl/commands/command.go @@ -294,7 +294,7 @@ func modifyCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error modifiedCommand, _, err := c.UpdateCommand(context.TODO(), command) if err != nil { - return fmt.Errorf("unable to modify command '%s'. %s", command.DisplayName, err.Error()) + return fmt.Errorf("unable to modify command '%s': %w", command.DisplayName, err) } printer.PrintT("modified command {{.DisplayName}}", modifiedCommand) @@ -316,7 +316,7 @@ func moveCommandCmdF(c client.Client, cmd *cobra.Command, args []string) error { resp, err := c.MoveCommand(context.TODO(), newTeam.Id, command.Id) if err != nil { - return fmt.Errorf("unable to move command '%s'. %s", command.Id, err.Error()) + return fmt.Errorf("unable to move command '%s': %w", command.Id, err) } if resp.StatusCode == http.StatusOK { diff --git a/server/cmd/mmctl/commands/command_test.go b/server/cmd/mmctl/commands/command_test.go index 109ead94a4..ec538004d2 100644 --- a/server/cmd/mmctl/commands/command_test.go +++ b/server/cmd/mmctl/commands/command_test.go @@ -741,7 +741,7 @@ func (s *MmctlUnitTestSuite) TestCommandModifyCmd() { s.Require().NotNil(err) s.Len(printer.GetLines(), 0) s.Len(printer.GetErrorLines(), 0) - s.EqualError(err, "unable to modify command '"+mockCommand.DisplayName+"'. "+mockError.Error()) + s.EqualError(err, "unable to modify command '"+mockCommand.DisplayName+"': "+mockError.Error()) }) } @@ -900,7 +900,7 @@ func (s *MmctlUnitTestSuite) TestCommandMoveCmd() { err := moveCommandCmdF(s.client, &cobra.Command{}, []string{teamArg, commandArg}) s.Require().NotNil(err) - s.Require().EqualError(err, "unable to move command '"+commandArg+"'. "+mockError.Error()) + s.Require().EqualError(err, "unable to move command '"+commandArg+"': "+mockError.Error()) s.Require().Len(printer.GetLines(), 0) s.Require().Len(printer.GetErrorLines(), 0) }) diff --git a/server/cmd/mmctl/commands/config.go b/server/cmd/mmctl/commands/config.go index 305072dedd..add760f203 100644 --- a/server/cmd/mmctl/commands/config.go +++ b/server/cmd/mmctl/commands/config.go @@ -222,7 +222,7 @@ func setValueWithConversion(val reflect.Value, newValue any) error { bits := val.Type().Bits() v, err := strconv.ParseInt(newValue.(string), 10, bits) if err != nil { - return fmt.Errorf("target value is of type %v and provided value is not, err: %v", val.Kind(), err) + return fmt.Errorf("target value is of type %v and provided value is not, err: %w", val.Kind(), err) } val.SetInt(v) return nil @@ -230,7 +230,7 @@ func setValueWithConversion(val reflect.Value, newValue any) error { bits := val.Type().Bits() v, err := strconv.ParseFloat(newValue.(string), bits) if err != nil { - return fmt.Errorf("target value is of type %v and provided value is not, err: %v", val.Kind(), err) + return fmt.Errorf("target value is of type %v and provided value is not, err: %w", val.Kind(), err) } val.SetFloat(v) return nil @@ -240,7 +240,7 @@ func setValueWithConversion(val reflect.Value, newValue any) error { case reflect.Bool: v, err := strconv.ParseBool(newValue.(string)) if err != nil { - return fmt.Errorf("target value is of type %v and provided value is not, err: %v", val.Kind(), err) + return fmt.Errorf("target value is of type %v and provided value is not, err: %w", val.Kind(), err) } val.SetBool(v) return nil diff --git a/server/cmd/mmctl/commands/post.go b/server/cmd/mmctl/commands/post.go index 0a790de309..a9377e45e6 100644 --- a/server/cmd/mmctl/commands/post.go +++ b/server/cmd/mmctl/commands/post.go @@ -118,7 +118,7 @@ func postCreateCmdF(c client.Client, cmd *cobra.Command, args []string) error { } if _, err := c.DoAPIPost(context.TODO(), url, data); err != nil { - return fmt.Errorf("could not create post: %s", err.Error()) + return fmt.Errorf("could not create post: %w", err) } return nil } diff --git a/server/cmd/mmctl/commands/user.go b/server/cmd/mmctl/commands/user.go index 7bbe3ce232..ff081f9f22 100644 --- a/server/cmd/mmctl/commands/user.go +++ b/server/cmd/mmctl/commands/user.go @@ -468,7 +468,7 @@ func changeUserActiveStatus(c client.Client, user *model.User, activate bool) er printer.Print("You must also deactivate user " + user.Id + " in the SSO provider or they will be reactivated on next login or sync.") } if _, err := c.UpdateUserActive(context.TODO(), user.Id, activate); err != nil { - return fmt.Errorf("unable to change activation status of user: %v", user.Id) + return fmt.Errorf("unable to change activation status of user %v: %w", user.Id, err) } return nil diff --git a/server/cmd/mmctl/commands/user_e2e_test.go b/server/cmd/mmctl/commands/user_e2e_test.go index 266595eab1..32e5bc8cf1 100644 --- a/server/cmd/mmctl/commands/user_e2e_test.go +++ b/server/cmd/mmctl/commands/user_e2e_test.go @@ -48,7 +48,7 @@ func (s *MmctlE2ETestSuite) TestUserActivateCmd() { s.Require().Error(err) s.Require().Len(printer.GetLines(), 0) s.Require().Len(printer.GetErrorLines(), 1) - s.Require().Equal(printer.GetErrorLines()[0], "unable to change activation status of user: "+user.Id) + s.Require().Equal(printer.GetErrorLines()[0], "unable to change activation status of user "+user.Id+": You do not have the appropriate permissions.") ruser, err := s.th.App.GetUser(user.Id) s.Require().Nil(err) @@ -98,7 +98,7 @@ func (s *MmctlE2ETestSuite) TestUserDeactivateCmd() { s.Require().Error(err) s.Require().Len(printer.GetLines(), 0) s.Require().Len(printer.GetErrorLines(), 1) - s.Require().Equal(printer.GetErrorLines()[0], "unable to change activation status of user: "+user.Id) + s.Require().Equal(printer.GetErrorLines()[0], "unable to change activation status of user "+user.Id+": You do not have the appropriate permissions.") ruser, err := s.th.App.GetUser(user.Id) s.Require().Nil(err) diff --git a/server/cmd/mmctl/commands/user_test.go b/server/cmd/mmctl/commands/user_test.go index 49c8c6d3a4..945714d799 100644 --- a/server/cmd/mmctl/commands/user_test.go +++ b/server/cmd/mmctl/commands/user_test.go @@ -94,7 +94,7 @@ func (s *MmctlUnitTestSuite) TestUserActivateCmd() { s.Require().Error(err) s.Require().Len(printer.GetLines(), 0) s.Require().Len(printer.GetErrorLines(), 1) - s.Require().Equal(fmt.Errorf("unable to change activation status of user: %v", mockUser.Id).Error(), printer.GetErrorLines()[0]) + s.Require().Equal(fmt.Sprintf("unable to change activation status of user %v: mock error", mockUser.Id), printer.GetErrorLines()[0]) }) s.Run("Activate several users with unexistent ones and failed ones", func() { @@ -170,7 +170,7 @@ func (s *MmctlUnitTestSuite) TestUserActivateCmd() { s.Require().Len(printer.GetLines(), 0) s.Require().Len(printer.GetErrorLines(), 2) s.Require().Equal(fmt.Sprintf("1 error occurred:\n\t* user %s not found\n\n", emailArgs[1]), printer.GetErrorLines()[0]) - s.Require().Equal(fmt.Sprintf("unable to change activation status of user: %v", mockUser3.Id), printer.GetErrorLines()[1]) + s.Require().Equal(fmt.Sprintf("unable to change activation status of user %v: mock error", mockUser3.Id), printer.GetErrorLines()[1]) }) s.Run("shell completion", func() { @@ -280,7 +280,7 @@ func (s *MmctlUnitTestSuite) TestDeactivateUserCmd() { s.Require().Error(err) s.Require().Len(printer.GetLines(), 0) s.Require().Len(printer.GetErrorLines(), 1) - s.Require().Equal(fmt.Errorf("unable to change activation status of user: %v", mockUser.Id).Error(), printer.GetErrorLines()[0]) + s.Require().Equal(fmt.Sprintf("unable to change activation status of user %v: mock error", mockUser.Id), printer.GetErrorLines()[0]) }) s.Run("Deactivate SSO user", func() { @@ -381,7 +381,7 @@ func (s *MmctlUnitTestSuite) TestDeactivateUserCmd() { s.Require().Equal("You must also deactivate user "+mockUser2.Id+" in the SSO provider or they will be reactivated on next login or sync.", printer.GetLines()[0]) s.Require().Len(printer.GetErrorLines(), 2) s.Require().Equal(fmt.Sprintf("1 error occurred:\n\t* user %v not found\n\n", emailArgs[1]), printer.GetErrorLines()[0]) - s.Require().Equal(fmt.Errorf("unable to change activation status of user: %v", mockUser3.Id).Error(), printer.GetErrorLines()[1]) + s.Require().Equal(fmt.Sprintf("unable to change activation status of user %v: mock error", mockUser3.Id), printer.GetErrorLines()[1]) }) }