summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/go/util/just_exit.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/client/go/util/just_exit.go b/client/go/util/just_exit.go
new file mode 100644
index 00000000000..1fab6cf0b4f
--- /dev/null
+++ b/client/go/util/just_exit.go
@@ -0,0 +1,50 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Author: arnej
+
+package util
+
+import (
+ "fmt"
+
+ "github.com/vespa-engine/vespa/client/go/trace"
+)
+
+type JustExitError struct {
+ err error
+ msg string
+}
+
+func (j *JustExitError) String() string {
+ if j.err != nil {
+ if j.msg == "" {
+ return j.err.Error()
+ }
+ return fmt.Sprintf("%s: %s", j.msg, j.err.Error())
+ }
+ if j.msg == "" {
+ panic(j)
+ }
+ return j.msg
+}
+
+func (j *JustExitError) Error() string {
+ return j.String()
+}
+
+func JustExitMsg(message string) {
+ trace.Trace("just exit with message")
+ j := JustExitError{
+ err: nil,
+ msg: message,
+ }
+ panic(&j)
+}
+
+func JustExitWith(e error) {
+ trace.Trace("just exit with error")
+ j := JustExitError{
+ err: e,
+ msg: "",
+ }
+ panic(&j)
+}