summaryrefslogtreecommitdiffstats
path: root/client/go
diff options
context:
space:
mode:
authorArne Juul <arnej@yahooinc.com>2022-10-25 11:23:25 +0000
committerArne Juul <arnej@yahooinc.com>2022-10-25 11:56:47 +0000
commit2f414d93e5497999b03843daba613730ac79365d (patch)
treed9de90d80b41fbadc408366d6f77a6648c3e549a /client/go
parent7c984e2ea7240dd6b491472c71ed5732a5bc8105 (diff)
add JustExitError
Diffstat (limited to 'client/go')
-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..a558a32fd11
--- /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 JustExit(message string) *JustExitError {
+ trace.Trace("just exit with message")
+ j := JustExitError{
+ err: nil,
+ msg: message,
+ }
+ return &j
+}
+
+func JustExitWith(e error) *JustExitError {
+ trace.Trace("just exit with error")
+ j := JustExitError{
+ err: e,
+ msg: "",
+ }
+ return &j
+}