print to stderr and exit(1) on failure

This commit is contained in:
Travis Nielsen committed 2016-10-19 15:40:40 -07:00
1 parent 7ea85102c1
commit b677542a75
10 files changed
+39 -11

No files matched your search

+3 -1
View File
@@ -3,6 +3,7 @@ package castle
import (
"fmt"
"net/http"
"os"
"github.com/quantum/castle/pkg/castle/client"
"github.com/quantum/castle/pkg/model"
@@ -43,7 +44,8 @@ func createBlockImagesEntry(cmd *cobra.Command, args []string) error {
c := client.NewCastleNetworkRestClient(client.GetRestURL(apiServerEndpoint), http.DefaultClient)
out, err := createBlockImage(newImageName, newImagePoolName, newImageSize, c)
if err != nil {
return err
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Println(out)
+3 -1
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"net/http"
"os"
"strings"
"github.com/quantum/castle/pkg/castle/client"
@@ -32,7 +33,8 @@ func listBlocksEntry(cmd *cobra.Command, args []string) error {
e := &exec.CommandExecutor{}
out, err := listBlocks(rbdSysBusPathDefault, c, e)
if err != nil {
return err
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Println(out)
+2 -1
View File
@@ -62,7 +62,8 @@ func mountBlockEntry(cmd *cobra.Command, args []string) error {
e := &exec.CommandExecutor{}
out, err := mountBlock(mountImageName, mountImagePoolName, mountImagePath, rbdSysBusPathDefault, c, e)
if err != nil {
return err
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Println(out)
+3 -1
View File
@@ -3,6 +3,7 @@ package castle
import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
@@ -37,7 +38,8 @@ func unmountBlockEntry(cmd *cobra.Command, args []string) error {
e := &exec.CommandExecutor{}
out, err := unmountBlock(unmountDeviceName, unmountPath, rbdSysBusPathDefault, e)
if err != nil {
return err
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Println(out)
+2 -1
View File
@@ -45,7 +45,8 @@ func Main() {
addCommands()
if err := rootCmd.Execute(); err != nil {
fmt.Printf("castle error: %+v\n", err)
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
+3 -1
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"net/http"
"os"
"github.com/quantum/castle/pkg/castle/client"
"github.com/quantum/castle/pkg/model"
@@ -26,7 +27,8 @@ func listNodesEntry(cmd *cobra.Command, args []string) error {
c := client.NewCastleNetworkRestClient(client.GetRestURL(apiServerEndpoint), http.DefaultClient)
out, err := listNodes(c)
if err != nil {
return err
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Print(out)
+3 -1
View File
@@ -3,6 +3,7 @@ package castle
import (
"fmt"
"net/http"
"os"
"github.com/quantum/castle/pkg/castle/client"
"github.com/quantum/castle/pkg/model"
@@ -56,7 +57,8 @@ func createPoolsEntry(cmd *cobra.Command, args []string) error {
c := client.NewCastleNetworkRestClient(client.GetRestURL(apiServerEndpoint), http.DefaultClient)
out, err := createPool(newPoolName, newPoolType, newPoolReplicaCount, newPoolDataChunks, newPoolCodingChunks, c)
if err != nil {
return err
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Println(out)
+3 -1
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"net/http"
"os"
"github.com/quantum/castle/pkg/castle/client"
"github.com/quantum/castle/pkg/model"
@@ -29,7 +30,8 @@ func listPoolsEntry(cmd *cobra.Command, args []string) error {
c := client.NewCastleNetworkRestClient(client.GetRestURL(apiServerEndpoint), http.DefaultClient)
out, err := listPools(c)
if err != nil {
return err
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Print(out)
+6 -1
View File
@@ -48,5 +48,10 @@ func runDaemon(cmd *cobra.Command, args []string) error {
}
// run the specified daemon
return cephd.New().RunDaemon(daemonType, os.Args[passthruIndex:]...)
if err := cephd.New().RunDaemon(daemonType, os.Args[passthruIndex:]...); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
return nil
}
+11 -2
View File
@@ -74,7 +74,7 @@ func init() {
// load the environment variables
setFlagsFromEnv(rootCmd.Flags())
rootCmd.RunE = joinCluster
rootCmd.RunE = startJoinCluster
}
func addCommands() {
@@ -82,12 +82,21 @@ func addCommands() {
rootCmd.AddCommand(daemonCmd)
}
func joinCluster(cmd *cobra.Command, args []string) error {
func startJoinCluster(cmd *cobra.Command, args []string) error {
// verify required flags
if err := flags.VerifyRequiredFlags(cmd, []string{}); err != nil {
return err
}
if err := joinCluster(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
return nil
}
func joinCluster() error {
// ensure the data root exists
if err := os.MkdirAll(cfg.dataDir, 0744); err != nil {
log.Printf("failed to create data directory at %s: %+v", cfg.dataDir, err)