From 8ca0c3bb58d2d70364cb07e62a311e789b320d8f Mon Sep 17 00:00:00 2001 From: Jason Song Date: Fri, 16 Aug 2024 18:16:20 +0800 Subject: [PATCH 1/2] fix: avoid return without written --- routers/web/repo/pull.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 9531482bee76e..3973b604af8b7 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -1308,9 +1308,10 @@ func CompareAndPullRequestPost(ctx *context.Context) { // instead of 500. if err := pull_service.NewPullRequest(ctx, repo, pullIssue, labelIDs, attachments, pullRequest, assigneeIDs); err != nil { - if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) { + switch { + case repo_model.IsErrUserDoesNotHaveAccessToRepo(err): ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err.Error()) - } else if git.IsErrPushRejected(err) { + case git.IsErrPushRejected(err): pushrejErr := err.(*git.ErrPushRejected) message := pushrejErr.Message if len(message) == 0 { @@ -1327,7 +1328,7 @@ func CompareAndPullRequestPost(ctx *context.Context) { return } ctx.JSONError(flashError) - } else if errors.Is(err, user_model.ErrBlockedUser) { + case errors.Is(err, user_model.ErrBlockedUser): flashError, err := ctx.RenderToHTML(tplAlertDetails, map[string]any{ "Message": ctx.Tr("repo.pulls.push_rejected"), "Summary": ctx.Tr("repo.pulls.new.blocked_user"), @@ -1337,7 +1338,7 @@ func CompareAndPullRequestPost(ctx *context.Context) { return } ctx.JSONError(flashError) - } else if errors.Is(err, issues_model.ErrMustCollaborator) { + case errors.Is(err, issues_model.ErrMustCollaborator): flashError, err := ctx.RenderToHTML(tplAlertDetails, map[string]any{ "Message": ctx.Tr("repo.pulls.push_rejected"), "Summary": ctx.Tr("repo.pulls.new.must_collaborator"), @@ -1347,6 +1348,11 @@ func CompareAndPullRequestPost(ctx *context.Context) { return } ctx.JSONError(flashError) + default: + // It's an unexpected error. + // Tf it happens, we should add another case to handle it. + log.Error("Unexpected error of NewPullRequest: %T %s", err, err) + ctx.ServerError("CompareAndPullRequest", err) } return } From 846f2765c3a6b5c35c207af588987dfd60288e07 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Fri, 16 Aug 2024 18:28:50 +0800 Subject: [PATCH 2/2] fix: typo --- routers/web/repo/pull.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 3973b604af8b7..e001e872aa8af 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -1350,7 +1350,7 @@ func CompareAndPullRequestPost(ctx *context.Context) { ctx.JSONError(flashError) default: // It's an unexpected error. - // Tf it happens, we should add another case to handle it. + // If it happens, we should add another case to handle it. log.Error("Unexpected error of NewPullRequest: %T %s", err, err) ctx.ServerError("CompareAndPullRequest", err) }