From 9316c4d826e813bcb26c520bfde4e4352ae9d67a Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Wed, 16 Aug 2023 15:32:05 +0200 Subject: Client + l18n: Make some errors internal only --- i18nerr/i18nerr.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'i18nerr') diff --git a/i18nerr/i18nerr.go b/i18nerr/i18nerr.go index 3520ecc..d513fdd 100644 --- a/i18nerr/i18nerr.go +++ b/i18nerr/i18nerr.go @@ -4,6 +4,7 @@ package i18nerr import ( "context" "errors" + "fmt" "sync" "github.com/eduvpn/eduvpn-common/internal/log" @@ -135,6 +136,26 @@ func Wrapf(err error, key message.Reference, args ...interface{}) *Error { return &Error{key: key, args: args, wrapped: &Error{key: t, Misc: misc}, Misc: misc} } +// NewInternalf creates an internal localised error from a display string +func NewInternal(disp string) *Error { + return Wrap(errors.New(disp), "An internal error occurred") +} + +// NewInternalf creates an internal localised error from a display string and arguments +func NewInternalf(disp string, args...interface{}) *Error { + return NewInternal(fmt.Sprintf(disp, args...)) +} + +// WrapInternal wraps an error and a display string into a localised internal error +func WrapInternal(err error, disp string) *Error { + return NewInternal(fmt.Sprintf("%s with internal cause: %v", disp, err)) +} + +// WrapInternalf wraps an error and a display string with args into a localised internal error +func WrapInternalf(err error, disp string, args ...interface{}) *Error { + return WrapInternal(err, fmt.Sprintf(disp, args...)) +} + // initializeLangs initializes the printers from the default catalog into the sync map // we cannot do this in init() because this is too early func inititializeLangs() { -- cgit v1.2.3