aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/cmd
diff options
context:
space:
mode:
authorArne Juul <arnej@yahooinc.com>2022-10-25 12:07:00 +0000
committerArne Juul <arnej@yahooinc.com>2022-10-28 09:40:10 +0000
commit1fe0f39c13bdf1500a4e6316a5cd6ebef482f68d (patch)
treec95e8d849b260f72642e3ae7ecaefc8700142050 /client/go/cmd
parent5a6d96e8d0b389131567d08af83eae2c9e23c141 (diff)
use JustExit
Diffstat (limited to 'client/go/cmd')
-rw-r--r--client/go/cmd/clusterstate/cluster_state.go6
-rw-r--r--client/go/cmd/clusterstate/detect_model.go7
-rw-r--r--client/go/cmd/clusterstate/set_node_state.go5
-rw-r--r--client/go/cmd/deploy/cmd.go3
-rw-r--r--client/go/cmd/deploy/curl.go7
-rw-r--r--client/go/cmd/deploy/fetch.go8
-rw-r--r--client/go/cmd/deploy/persist.go13
7 files changed, 29 insertions, 20 deletions
diff --git a/client/go/cmd/clusterstate/cluster_state.go b/client/go/cmd/clusterstate/cluster_state.go
index 5f8a1d7079f..2849e1aaf95 100644
--- a/client/go/cmd/clusterstate/cluster_state.go
+++ b/client/go/cmd/clusterstate/cluster_state.go
@@ -11,6 +11,7 @@ import (
"strings"
"github.com/vespa-engine/vespa/client/go/trace"
+ "github.com/vespa-engine/vespa/client/go/util"
)
// common struct used various places in the clustercontroller REST api:
@@ -101,7 +102,7 @@ func (model *VespaModelConfig) getClusterState(cluster string) (*ClusterState, *
var buf bytes.Buffer
err := curlGet(url, &buf)
if err != nil {
- errs = append(errs, "could not get:"+url)
+ errs = append(errs, "could not get: "+url)
continue
}
codec := json.NewDecoder(&buf)
@@ -116,5 +117,6 @@ func (model *VespaModelConfig) getClusterState(cluster string) (*ClusterState, *
return &parsedJson, &cc
}
// no success:
- panic(errs)
+ util.JustExitMsg(fmt.Sprint(errs))
+ panic("unreachable")
}
diff --git a/client/go/cmd/clusterstate/detect_model.go b/client/go/cmd/clusterstate/detect_model.go
index d1b2bd80d66..61af9c03e21 100644
--- a/client/go/cmd/clusterstate/detect_model.go
+++ b/client/go/cmd/clusterstate/detect_model.go
@@ -21,7 +21,7 @@ func getConfigServerHosts(s string) []string {
got, err := backticks.Run(vespa.FindHome()+"/bin/vespa-print-default", "configservers")
res := strings.Fields(got)
if err != nil || len(res) < 1 {
- panic("bad configservers: " + got)
+ util.JustExitMsg("bad configservers: " + got)
}
trace.Debug("found", len(res), "configservers:", res)
return res
@@ -37,7 +37,7 @@ func getConfigServerPort(i int) int {
i, err = strconv.Atoi(strings.TrimSpace(got))
}
if err != nil || i < 1 {
- panic("bad configserver_rpc_port: " + got)
+ util.JustExitMsg("bad configserver_rpc_port: " + got)
}
trace.Debug("found configservers rpc port:", i)
return i
@@ -62,5 +62,6 @@ func detectModel(opts *Options) *VespaModelConfig {
return parsed
}
}
- panic("could not get model config")
+ util.JustExitMsg("could not get model config")
+ panic("unreachable")
}
diff --git a/client/go/cmd/clusterstate/set_node_state.go b/client/go/cmd/clusterstate/set_node_state.go
index ad0977d1c4b..419fddc3692 100644
--- a/client/go/cmd/clusterstate/set_node_state.go
+++ b/client/go/cmd/clusterstate/set_node_state.go
@@ -15,6 +15,7 @@ import (
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/build"
"github.com/vespa-engine/vespa/client/go/trace"
+ "github.com/vespa-engine/vespa/client/go/util"
)
const (
@@ -78,7 +79,7 @@ func runSetNodeState(opts *Options, args []string) {
}
wanted, err := knownState(args[0])
if err != nil {
- panic(err)
+ util.JustExitWith(err)
}
reason := ""
if len(args) > 1 {
@@ -136,7 +137,7 @@ func (cc *ClusterControllerSpec) setNodeUserState(s serviceSpec, wanted KnownSta
}
jsonBytes, err := json.Marshal(request)
if err != nil {
- panic(err)
+ util.JustExitWith(err)
}
url := fmt.Sprintf("http://%s:%d/cluster/v2/%s/%s/%d",
cc.host, cc.port,
diff --git a/client/go/cmd/deploy/cmd.go b/client/go/cmd/deploy/cmd.go
index bf21ffce59f..39111b80d01 100644
--- a/client/go/cmd/deploy/cmd.go
+++ b/client/go/cmd/deploy/cmd.go
@@ -11,6 +11,7 @@ import (
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/build"
"github.com/vespa-engine/vespa/client/go/trace"
+ "github.com/vespa-engine/vespa/client/go/util"
"github.com/vespa-engine/vespa/client/go/vespa"
)
@@ -23,7 +24,7 @@ func NewDeployCmd() *cobra.Command {
curOptions Options
)
if err := vespa.LoadDefaultEnv(); err != nil {
- panic(err)
+ util.JustExitWith(err)
}
cobra.EnableCommandSorting = false
cmd := &cobra.Command{
diff --git a/client/go/cmd/deploy/curl.go b/client/go/cmd/deploy/curl.go
index cc55cbc7e4b..92b5cead0e9 100644
--- a/client/go/cmd/deploy/curl.go
+++ b/client/go/cmd/deploy/curl.go
@@ -14,6 +14,7 @@ import (
"github.com/vespa-engine/vespa/client/go/curl"
"github.com/vespa-engine/vespa/client/go/trace"
+ "github.com/vespa-engine/vespa/client/go/util"
"github.com/vespa-engine/vespa/client/go/vespa"
)
@@ -59,20 +60,20 @@ func urlWithoutQuery(url string) string {
func newCurlCommand(url string, args []string) *curl.Command {
tls, err := vespa.LoadTlsConfig()
if err != nil {
- panic(err)
+ util.JustExitWith(err)
}
if tls != nil && strings.HasPrefix(url, "http:") {
url = "https:" + url[5:]
}
cmd, err := curl.RawArgs(url, args...)
if err != nil {
- panic(err)
+ util.JustExitWith(err)
}
if tls != nil {
if tls.DisableHostnameValidation {
cmd, err = curl.RawArgs(url, append(args, "--insecure")...)
if err != nil {
- panic(err)
+ util.JustExitWith(err)
}
}
cmd.PrivateKey = tls.Files.PrivateKey
diff --git a/client/go/cmd/deploy/fetch.go b/client/go/cmd/deploy/fetch.go
index 3b65509c0a3..3936ecd5ecb 100644
--- a/client/go/cmd/deploy/fetch.go
+++ b/client/go/cmd/deploy/fetch.go
@@ -11,6 +11,8 @@ import (
"os"
"strconv"
"strings"
+
+ "github.com/vespa-engine/vespa/client/go/util"
)
// main entry point for vespa-deploy fetch
@@ -87,8 +89,8 @@ func getPartAfterSlash(path string) string {
if idx > 1 && parts[idx] == "" {
return parts[idx-1]
}
- if idx > 0 {
- return parts[idx]
+ if idx == 0 {
+ util.JustExitMsg("cannot find part after slash: " + path)
}
- panic("cannot find part after slash: " + path)
+ return parts[idx]
}
diff --git a/client/go/cmd/deploy/persist.go b/client/go/cmd/deploy/persist.go
index 682e7b13674..1ccb24f437e 100644
--- a/client/go/cmd/deploy/persist.go
+++ b/client/go/cmd/deploy/persist.go
@@ -9,6 +9,7 @@ import (
"path/filepath"
"github.com/vespa-engine/vespa/client/go/trace"
+ "github.com/vespa-engine/vespa/client/go/util"
)
const (
@@ -40,11 +41,11 @@ func configsourceUrlUsedFile() string {
func createTenantDir(tenant string) string {
home, err := createCloudconfigDir()
if err != nil {
- panic(err)
+ util.JustExitWith(err)
}
tdir := filepath.Join(home, tenant)
if err := os.MkdirAll(tdir, 0700); err != nil {
- panic(err)
+ util.JustExitWith(err)
}
return tdir
}
@@ -76,9 +77,9 @@ func getSessionIdFromFile(tenant string) string {
dir := createTenantDir(tenant)
fn := filepath.Join(dir, sessionIdFileName)
bytes, err := os.ReadFile(fn)
- if err == nil {
- trace.Trace("Session-id", string(bytes), "found from file", fn)
- return string(bytes)
+ if err != nil {
+ util.JustExitMsg("Could not read session id from file, and no session id supplied as argument. Exiting.")
}
- panic("Could not read session id from file, and no session id supplied as argument. Exiting.")
+ trace.Trace("Session-id", string(bytes), "found from file", fn)
+ return string(bytes)
}