Fix missing errors in mmctl output (#30567)

Этот коммит содержится в:
Ben Schumacher
2025-03-28 09:30:41 +01:00
коммит произвёл GitHub
родитель 4156112f7c
Коммит 6c8235d031
7 изменённых файлов: 15 добавлений и 15 удалений

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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)
})

Просмотреть файл

@@ -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

Просмотреть файл

@@ -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
}

Просмотреть файл

@@ -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

Просмотреть файл

@@ -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)

Просмотреть файл

@@ -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])
})
}