1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Refactor error system (#33771)

It should not expose `util.SilentWrap` or construct it manually.
This commit is contained in:
wxiaoguang
2025-03-03 13:36:10 +08:00
committed by GitHub
parent dbed39d632
commit 216243eee2
12 changed files with 41 additions and 58 deletions

View File

@@ -1,13 +0,0 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package i18n
import (
"code.gitea.io/gitea/modules/util"
)
var (
ErrLocaleAlreadyExist = util.SilentWrap{Message: "lang already exists", Err: util.ErrAlreadyExist}
ErrUncertainArguments = util.SilentWrap{Message: "arguments to i18n should not contain uncertain slices", Err: util.ErrInvalidArgument}
)

View File

@@ -4,6 +4,7 @@
package i18n
import (
"errors"
"fmt"
"reflect"
)
@@ -30,7 +31,7 @@ func Format(format string, args ...any) (msg string, err error) {
fmtArgs = append(fmtArgs, val.Index(i).Interface())
}
} else {
err = ErrUncertainArguments
err = errors.New("arguments to i18n should not contain uncertain slices")
break
}
} else {

View File

@@ -4,6 +4,7 @@
package i18n
import (
"errors"
"fmt"
"html/template"
"slices"
@@ -41,7 +42,7 @@ func NewLocaleStore() LocaleStore {
// AddLocaleByIni adds locale by ini into the store
func (store *localeStore) AddLocaleByIni(langName, langDesc string, source, moreSource []byte) error {
if _, ok := store.localeMap[langName]; ok {
return ErrLocaleAlreadyExist
return errors.New("lang has already been added")
}
store.langNames = append(store.langNames, langName)