diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-08-16 15:32:05 +0200 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2023-09-25 09:43:37 +0200 |
| commit | 9316c4d826e813bcb26c520bfde4e4352ae9d67a (patch) | |
| tree | 1846906f9a79c9d58a640c1a13c6c71ad825a3d5 /i18nerr/i18nerr.go | |
| parent | 15588a55a8c00fcfd9994eb87cff91c352a850d4 (diff) | |
Client + l18n: Make some errors internal only
Diffstat (limited to 'i18nerr/i18nerr.go')
| -rw-r--r-- | i18nerr/i18nerr.go | 21 |
1 files changed, 21 insertions, 0 deletions
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() { |
