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 12:25:06 +02:00
committed by GitHub
parent fac8bf2eca
commit 76a81b24f9
248 changed files with 1110 additions and 995 deletions
+5 -7
View File
@@ -100,9 +100,8 @@ func DisableTwoFactor(ctx *context.Context) {
func twofaGenerateSecretAndQr(ctx *context.Context) bool {
var otpKey *otp.Key
var err error
uri := ctx.Session.Get("twofaUri")
if uri != nil {
otpKey, err = otp.NewKeyFromURL(uri.(string))
if uri, ok := ctx.Session.Get("twofaUri").(string); ok {
otpKey, err = otp.NewKeyFromURL(uri)
if err != nil {
ctx.ServerError("SettingsTwoFactor: Failed NewKeyFromURL: ", err)
return false
@@ -193,7 +192,7 @@ func EnrollTwoFactorPost(ctx *context.Context) {
return
}
form := web.GetForm(ctx).(*forms.TwoFactorAuthForm)
form := web.GetForm[*forms.TwoFactorAuthForm](ctx)
ctx.Data["Title"] = ctx.Tr("settings_title")
ctx.Data["PageIsSettingsSecurity"] = true
ctx.Data["ShowTwoFactorRequiredMessage"] = false
@@ -218,14 +217,13 @@ func EnrollTwoFactorPost(ctx *context.Context) {
return
}
secretRaw := ctx.Session.Get("twofaSecret")
if secretRaw == nil {
secret, ok := ctx.Session.Get("twofaSecret").(string)
if !ok {
ctx.Flash.Error(ctx.Tr("settings.twofa_failed_get_secret"))
ctx.Redirect(setting.AppSubURL + "/user/settings/security/two_factor/enroll")
return
}
secret := secretRaw.(string)
if !totp.Validate(form.Passcode, secret) {
if !twofaGenerateSecretAndQr(ctx) {
return
+1 -1
View File
@@ -24,7 +24,7 @@ func OpenIDPost(ctx *context.Context) {
return
}
form := web.GetForm(ctx).(*forms.AddOpenIDForm)
form := web.GetForm[*forms.AddOpenIDForm](ctx)
ctx.Data["Title"] = ctx.Tr("settings_title")
ctx.Data["PageIsSettingsSecurity"] = true
@@ -30,7 +30,7 @@ func WebAuthnRegister(ctx *context.Context) {
return
}
form := web.GetForm(ctx).(*forms.WebauthnRegistrationForm)
form := web.GetForm[*forms.WebauthnRegistrationForm](ctx)
if form.Name == "" {
// Set name to the hexadecimal of the current time
form.Name = strconv.FormatInt(time.Now().UnixNano(), 16)