Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor error system #33610

Merged
merged 6 commits into from
Feb 17, 2025
Merged

Refactor error system #33610

merged 6 commits into from
Feb 17, 2025

Conversation

wxiaoguang
Copy link
Contributor

@wxiaoguang wxiaoguang commented Feb 16, 2025

No description provided.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 16, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Feb 16, 2025
@pull-request-size pull-request-size bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Feb 16, 2025
@wxiaoguang
Copy link
Contributor Author

The error system was abused a lot. For example: does anyone could understand what would happen?

ctx.NotFound("", nil)
ctx.NotFound("", err)
ctx.NotFound("MustAllowPulls", nil)
ctx.NotFound(fmt.Sprintf("Unknown action %s", ctx.PathParam("action")), nil)
ctx.NotFound("Not Found", fmt.Errorf("keys setting is not allowed to be changed"))

ctx.Error(http.StatusInternalServerError, "", ctx.Tr("repo.migrate.invalid_lfs_endpoint"))

This PR is the first step to cleanup the error system.

In the future, ideally we should only call something like ctx.APIErrorInternal(err) and ctx.NotFound("the message"), it doesn't make sense to duplicate some function names as "title" again and again. There are already filenames and line numbers in the error log.

@@ -42,7 +42,7 @@ func GetAllEmails(ctx *context.APIContext) {
ListOptions: listOptions,
})
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetAllEmails", err)
ctx.APIError(http.StatusInternalServerError, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ctx.APIError(http.StatusInternalServerError, err)
ctx.APIErrorInternal(err)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is the first step to cleanup the error system.

There are too many, I will leave them to the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next: Refactor error system #33626

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 16, 2025
@lunny lunny added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Feb 16, 2025

ctx.JSON(http.StatusInternalServerError, APIError{
Message: message,
URL: setting.API.SwaggerURL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that code was simply moved.
Still, it looks counter-intuitive to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's another copy-paste problem in history, people just keep copying unclear code everywhere ......... that's why it needs to regularly maintain the legacy code ........

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More backgrounds: the URL field is a quite old design from old code.

I have managed to add some comments for the URL field, that's all what I can do at the moment:

https://github.com/go-gitea/gitea/pull/18111/commits/01f2dfc26236d2066c2901b5fb0845db04652643

01f2dfc

image

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 16, 2025
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 17, 2025
@lunny lunny enabled auto-merge (squash) February 17, 2025 01:47
@lunny lunny disabled auto-merge February 17, 2025 01:47
@lunny lunny merged commit f35850f into go-gitea:main Feb 17, 2025
26 checks passed
@GiteaBot GiteaBot added this to the 1.24.0 milestone Feb 17, 2025
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Feb 17, 2025
@wxiaoguang wxiaoguang deleted the refactor-err branch February 17, 2025 06:13
zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 18, 2025
* giteaofficial/main:
  Make actions URL in commit status webhooks absolute (go-gitea#33620)
  Refactor error system (go-gitea#33626)
  Move issue pin to an standalone table for querying performance (go-gitea#33452)
  Run spellcheck on tools directory (go-gitea#33627)
  Refactor error system (go-gitea#33610)
  Fix project issues list and counting (go-gitea#33594)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants