diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2025-02-11 03:05:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-11 03:05:42 +0800 |
commit | 30993e95082356daa40b3605bff65b565e913bcc (patch) | |
tree | decb86d86ce6bbc783f5b72ff297eb98db378f1a /modules/util | |
parent | 085f273d19a30cc7cb7f6315a15a95c2b59fc5b9 (diff) | |
download | gitea-30993e95082356daa40b3605bff65b565e913bcc.tar.gz gitea-30993e95082356daa40b3605bff65b565e913bcc.zip |
Feature: Support workflow event dispatch via API (#33545)
Fix: https://github.com/go-gitea/gitea/issues/31765 (Re-open #32059)
---------
Co-authored-by: Bence Santha <git@santha.eu>
Co-authored-by: Bence Sántha <7604637+bencurio@users.noreply.github.com>
Co-authored-by: Christopher Homberger <christopher.homberger@web.de>
Diffstat (limited to 'modules/util')
-rw-r--r-- | modules/util/error.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/modules/util/error.go b/modules/util/error.go index 0f3597147c..07fadf3cab 100644 --- a/modules/util/error.go +++ b/modules/util/error.go @@ -36,6 +36,22 @@ func (w SilentWrap) Unwrap() error { return w.Err } +type LocaleWrap struct { + err error + TrKey string + TrArgs []any +} + +// Error returns the message +func (w LocaleWrap) Error() string { + return w.err.Error() +} + +// Unwrap returns the underlying error +func (w LocaleWrap) Unwrap() error { + return w.err +} + // NewSilentWrapErrorf returns an error that formats as the given text but unwraps as the provided error func NewSilentWrapErrorf(unwrap error, message string, args ...any) error { if len(args) == 0 { @@ -63,3 +79,16 @@ func NewAlreadyExistErrorf(message string, args ...any) error { func NewNotExistErrorf(message string, args ...any) error { return NewSilentWrapErrorf(ErrNotExist, message, args...) } + +// ErrWrapLocale wraps an err with a translation key and arguments +func ErrWrapLocale(err error, trKey string, trArgs ...any) error { + return LocaleWrap{err: err, TrKey: trKey, TrArgs: trArgs} +} + +func ErrAsLocale(err error) *LocaleWrap { + var e LocaleWrap + if errors.As(err, &e) { + return &e + } + return nil +} |