aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/util/just_exit.go
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2023-02-03 15:20:23 +0100
committerMartin Polden <mpolden@mpolden.no>2023-02-03 15:35:25 +0100
commite1e94812425a487069bf33f781bec987e9e49874 (patch)
tree4a892c3b5c0a7dee2cb76f9971e538cb4aba8a16 /client/go/internal/util/just_exit.go
parenta08ae588d6035b69f0961dff596fc871fd1c4e58 (diff)
Re-organize Go code
Diffstat (limited to 'client/go/internal/util/just_exit.go')
-rw-r--r--client/go/internal/util/just_exit.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/client/go/internal/util/just_exit.go b/client/go/internal/util/just_exit.go
new file mode 100644
index 00000000000..b05430adcde
--- /dev/null
+++ b/client/go/internal/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/internal/admin/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)
+}