Print & Return errors using multierror if an error happens (#26625)

* Print & Return errors using multierror if an error happens

* Group up errors assertion in test

* Remove trailing newspace

* Remove WrappedErrors loop

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Ezekiel
2024-05-01 04:16:05 +08:00
коммит произвёл GitHub
родитель 48b047aa0c
Коммит b7e830f4a1
3 изменённых файлов: 43 добавлений и 34 удалений

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

@@ -368,18 +368,24 @@ func unarchiveChannelsCmdF(c client.Client, cmd *cobra.Command, args []string) e
return errors.New("enter at least one channel")
}
var errs *multierror.Error
channels := getChannelsFromChannelArgs(c, args)
for i, channel := range channels {
if channel == nil {
printer.PrintError("Unable to find channel '" + args[i] + "'")
msg := "Unable to find channel '" + args[i] + "'"
printer.PrintError(msg)
errs = multierror.Append(errs, errors.New(msg))
continue
}
if _, _, err := c.RestoreChannel(context.TODO(), channel.Id); err != nil {
printer.PrintError("Unable to unarchive channel '" + args[i] + "'. Error: " + err.Error())
msg := "Unable to unarchive channel '" + args[i] + "'. Error: " + err.Error()
printer.PrintError(msg)
errs = multierror.Append(errs, errors.New(msg))
}
}
return nil
return errs.ErrorOrNil()
}
func makeChannelPrivateCmdF(c client.Client, cmd *cobra.Command, args []string) error {