chore: enable forcetypeassert linter, fix issues (#38804)

Enable [`forcetypeassert`](https://github.com/gostaticanalysis/forcetypeassert)
linter to prevent unchecked type assertions. ~650 issues fixed, most
fixes were clean, some use `setting.PanicInDevOrTesting`.

The only behaviour changes are where code would previously send a 500 error
or panic, a 4xx error is now emitted.

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
silverwind
2026-08-09 10:25:06 +00:00
committed by GitHub
co-authored by wxiaoguang
parent fac8bf2eca
commit 76a81b24f9
248 changed files with 1110 additions and 995 deletions
+4 -4
View File
@@ -63,15 +63,15 @@ func AddEmail(ctx *context.APIContext) {
return
}
form := web.GetForm(ctx).(*api.CreateEmailOption)
form := web.GetForm[*api.CreateEmailOption](ctx)
if len(form.Emails) == 0 {
ctx.APIError(http.StatusUnprocessableEntity, "Email list empty")
return
}
if err := user_service.AddEmailAddresses(ctx, ctx.Doer, form.Emails); err != nil {
if user_model.IsErrEmailAlreadyUsed(err) {
ctx.APIError(http.StatusUnprocessableEntity, "Email address has been used: "+err.(user_model.ErrEmailAlreadyUsed).Email)
if errEmailAlreadyUsed, ok := err.(user_model.ErrEmailAlreadyUsed); ok {
ctx.APIError(http.StatusUnprocessableEntity, "Email address has been used: "+errEmailAlreadyUsed.Email)
} else if user_model.IsErrEmailCharIsNotSupported(err) || user_model.IsErrEmailInvalid(err) {
email := ""
if typedError, ok := err.(user_model.ErrEmailInvalid); ok {
@@ -125,7 +125,7 @@ func DeleteEmail(ctx *context.APIContext) {
return
}
form := web.GetForm(ctx).(*api.DeleteEmailOption)
form := web.GetForm[*api.DeleteEmailOption](ctx)
if len(form.Emails) == 0 {
ctx.Status(http.StatusNoContent)
return