summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorArne H Juul <arnej27959@users.noreply.github.com>2022-10-28 11:20:13 +0200
committerGitHub <noreply@github.com>2022-10-28 11:20:13 +0200
commit5a6d96e8d0b389131567d08af83eae2c9e23c141 (patch)
tree09a7f153bbbb03e4e34a860527e1366189a3623a /client
parentd66f9b3bcd71c8fecd0afd6583c699d7d2bcd8bb (diff)
parentb3458e274bdce76dc6f1852388bd5a4c8bcb17f6 (diff)
Merge pull request #24575 from vespa-engine/arnej/add-just-exit-error
Arnej/add just exit error
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)
+}