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
+13 -9
View File
@@ -56,7 +56,7 @@ func Migrate(ctx *context.APIContext) {
// "422":
// "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.MigrateRepoOptions)
form := web.GetForm[*api.MigrateRepoOptions](ctx)
// get repoOwner
var (
@@ -217,6 +217,11 @@ func Migrate(ctx *context.APIContext) {
}
func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, err error) {
var (
errNameReserved db.ErrNameReserved
errNameCharsNotAllowed db.ErrNameCharsNotAllowed
errNamePatternNotAllowed db.ErrNamePatternNotAllowed
)
switch {
case repo_model.IsErrRepoAlreadyExist(err):
ctx.APIError(http.StatusConflict, "The repository with the same name already exists.")
@@ -228,12 +233,12 @@ func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, err
ctx.APIError(http.StatusUnprocessableEntity, "Remote visit required two factors authentication.")
case repo_model.IsErrReachLimitOfRepo(err):
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("You have already reached your limit of %d repositories.", repoOwner.MaxCreationLimit()))
case db.IsErrNameReserved(err):
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The username '%s' is reserved.", err.(db.ErrNameReserved).Name))
case db.IsErrNameCharsNotAllowed(err):
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The username '%s' contains invalid characters.", err.(db.ErrNameCharsNotAllowed).Name))
case db.IsErrNamePatternNotAllowed(err):
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The pattern '%s' is not allowed in a username.", err.(db.ErrNamePatternNotAllowed).Pattern))
case errors.As(err, &errNameReserved):
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The username '%s' is reserved.", errNameReserved.Name))
case errors.As(err, &errNameCharsNotAllowed):
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The username '%s' contains invalid characters.", errNameCharsNotAllowed.Name))
case errors.As(err, &errNamePatternNotAllowed):
ctx.APIError(http.StatusUnprocessableEntity, fmt.Sprintf("The pattern '%s' is not allowed in a username.", errNamePatternNotAllowed.Pattern))
case git.IsErrInvalidCloneAddr(err):
ctx.APIError(http.StatusUnprocessableEntity, err.Error())
case base.IsErrNotSupported(err):
@@ -253,8 +258,7 @@ func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, err
}
func handleRemoteAddrError(ctx *context.APIContext, err error) {
if git.IsErrInvalidCloneAddr(err) {
addrErr := err.(*git.ErrInvalidCloneAddr)
if addrErr, ok := err.(*git.ErrInvalidCloneAddr); ok {
switch {
case addrErr.IsURLError:
ctx.APIError(http.StatusUnprocessableEntity, "The provided URL is invalid.")