[MM-47824] fix promoteGuestToUserCmdF to handle the proper errors (#26397)

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
FutureFoodBanker
2024-03-22 20:42:37 +08:00
коммит произвёл GitHub
родитель 7337c384a8
Коммит 46bd4599f0
3 изменённых файлов: 11 добавлений и 6 удалений

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

@@ -1024,21 +1024,26 @@ func migrateAuthToLdapCmdF(c client.Client, cmd *cobra.Command, userArgs []strin
}
func promoteGuestToUserCmdF(c client.Client, _ *cobra.Command, userArgs []string) error {
var errs *multierror.Error
for i, user := range getUsersFromUserArgs(c, userArgs) {
if user == nil {
printer.PrintError(fmt.Sprintf("can't find guest '%v'", userArgs[i]))
err := fmt.Errorf("can't find guest '%s'", userArgs[i])
errs = multierror.Append(errs, err)
printer.PrintError(err.Error())
continue
}
if _, err := c.PromoteGuestToUser(context.TODO(), user.Id); err != nil {
printer.PrintError(fmt.Sprintf("unable to promote guest %s: %s", userArgs[i], err))
err = fmt.Errorf("unable to promote guest %s: %w", userArgs[i], err)
errs = multierror.Append(errs, err)
printer.PrintError(err.Error())
continue
}
printer.PrintT("User {{.Username}} promoted.", user)
}
return nil
return errs.ErrorOrNil()
}
func demoteUserToGuestCmdF(c client.Client, _ *cobra.Command, userArgs []string) error {