Make CLI functions return error instead of fatal out (#1379)
Before this PR, CLI functions fatal out when encountering error instead of returning it. Such behavior makes it hard to reuse the functions nor writing unit tests. This PR aims to make functions return errors instead of error out.
This commit is contained in:
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/log"
|
||||
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
)
|
||||
|
||||
@@ -53,7 +53,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
case CrdEnvironment:
|
||||
items, err := res.client.EnvironmentList(metav1.NamespaceAll)
|
||||
if err != nil {
|
||||
log.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
case CrdFunction:
|
||||
items, err := res.client.FunctionList(metav1.NamespaceAll)
|
||||
if err != nil {
|
||||
log.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
case CrdPackage:
|
||||
items, err := res.client.PackageList(metav1.NamespaceAll)
|
||||
if err != nil {
|
||||
log.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
case CrdHttpTrigger:
|
||||
items, err := res.client.HTTPTriggerList(metav1.NamespaceAll)
|
||||
if err != nil {
|
||||
log.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
case CrdKubeWatcher:
|
||||
items, err := res.client.WatchList(metav1.NamespaceAll)
|
||||
if err != nil {
|
||||
log.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
for _, mqType := range []string{types.MessageQueueTypeNats, types.MessageQueueTypeASQ} {
|
||||
l, err := res.client.MessageQueueTriggerList(mqType, metav1.NamespaceAll)
|
||||
if err != nil {
|
||||
log.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
break
|
||||
}
|
||||
triggers = append(triggers, l...)
|
||||
@@ -131,7 +131,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
case CrdTimeTrigger:
|
||||
items, err := res.client.TimeTriggerList(metav1.NamespaceAll)
|
||||
if err != nil {
|
||||
log.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
consolemsg.Info(fmt.Sprintf("Error getting %v list: %v", res.crdType, err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func (res CrdDumper) Dump(dumpDir string) {
|
||||
}
|
||||
|
||||
default:
|
||||
log.Info(fmt.Sprintf("Unknown type: %v", res.crdType))
|
||||
consolemsg.Info(fmt.Sprintf("Unknown type: %v", res.crdType))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user