From 2f414d93e5497999b03843daba613730ac79365d Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Tue, 25 Oct 2022 11:23:25 +0000 Subject: add JustExitError --- client/go/util/just_exit.go | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 client/go/util/just_exit.go (limited to 'client/go') 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 +} -- cgit v1.2.3