Add idiomatic error handling in mattermost commands (#9147)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
da124f018d
Коммит
bfb2640451
@@ -90,9 +90,13 @@ func configSubpathCmdF(command *cobra.Command, args []string) error {
|
||||
path, err := command.Flags().GetString("path")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed reading path")
|
||||
} else if path == "" {
|
||||
}
|
||||
|
||||
if path == "" {
|
||||
return utils.UpdateAssetsSubpathFromConfig(a.Config())
|
||||
} else if err := utils.UpdateAssetsSubpath(path); err != nil {
|
||||
}
|
||||
|
||||
if err := utils.UpdateAssetsSubpath(path); err != nil {
|
||||
return errors.Wrap(err, "failed to update assets subpath")
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,9 @@ func bulkImportCmdF(command *cobra.Command, args []string) error {
|
||||
if apply && validate {
|
||||
CommandPrettyPrintln("Use only one of --apply or --validate.")
|
||||
return nil
|
||||
} else if apply && !validate {
|
||||
}
|
||||
|
||||
if apply && !validate {
|
||||
CommandPrettyPrintln("Running Bulk Import. This may take a long time.")
|
||||
} else {
|
||||
CommandPrettyPrintln("Running Bulk Import Data Validation.")
|
||||
@@ -141,12 +143,12 @@ func bulkImportCmdF(command *cobra.Command, args []string) error {
|
||||
CommandPrettyPrintln(fmt.Sprintf("Error occurred on data file line %v", lineNumber))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
if apply {
|
||||
CommandPrettyPrintln("Finished Bulk Import.")
|
||||
} else {
|
||||
if apply {
|
||||
CommandPrettyPrintln("Finished Bulk Import.")
|
||||
} else {
|
||||
CommandPrettyPrintln("Validation complete. You can now perform the import by rerunning this command with the --apply flag.")
|
||||
}
|
||||
CommandPrettyPrintln("Validation complete. You can now perform the import by rerunning this command with the --apply flag.")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -78,23 +78,27 @@ func scheduleExportCmdF(command *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
// for now, format is hard-coded to actiance. In time, we'll have to support other formats and inject them into job data
|
||||
if format, err := command.Flags().GetString("format"); err != nil {
|
||||
format, err := command.Flags().GetString("format")
|
||||
if err != nil {
|
||||
return errors.New("format flag error")
|
||||
} else if format != "actiance" {
|
||||
}
|
||||
if format != "actiance" {
|
||||
return errors.New("unsupported export format")
|
||||
}
|
||||
|
||||
startTime, err := command.Flags().GetInt64("exportFrom")
|
||||
if err != nil {
|
||||
return errors.New("exportFrom flag error")
|
||||
} else if startTime < 0 {
|
||||
}
|
||||
if startTime < 0 {
|
||||
return errors.New("exportFrom must be a positive integer")
|
||||
}
|
||||
|
||||
timeoutSeconds, err := command.Flags().GetInt("timeoutSeconds")
|
||||
if err != nil {
|
||||
return errors.New("timeoutSeconds error")
|
||||
} else if timeoutSeconds < 0 {
|
||||
}
|
||||
if timeoutSeconds < 0 {
|
||||
return errors.New("timeoutSeconds must be a positive integer")
|
||||
}
|
||||
|
||||
@@ -128,7 +132,8 @@ func buildExportCmdF(format string) func(command *cobra.Command, args []string)
|
||||
startTime, err := command.Flags().GetInt64("exportFrom")
|
||||
if err != nil {
|
||||
return errors.New("exportFrom flag error")
|
||||
} else if startTime < 0 {
|
||||
}
|
||||
if startTime < 0 {
|
||||
return errors.New("exportFrom must be a positive integer")
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user