-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 internal API for git commands, use meaningful messages instead of "Internal Server Error" #23687
Conversation
528885c
to
56914d4
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
56914d4
to
3c42039
Compare
This PR is ready for review |
760926f
to
5c83c6b
Compare
a35f8ce
to
949cb5d
Compare
949cb5d
to
9dfa002
Compare
I think something maybe wrong when push via ssh protocol but clone is OK.
|
The "push" should have been covered by tests. How do you reproduce it? According to "internal API error response, status=403", I guess it's related to some permission or protection problem during your test? |
Just clone and push. I'm the admin of this instance. |
My plan is to fine tune more messages in the future, and we have enough time to eat our own dogfood. At least, it's much easier than before to provide more friendly messages to end users. Made a fix for the log output, could you try if the new commit could output the friendly messages? |
Co-authored-by: delvh <[email protected]>
# Conflicts: # contrib/pr/checkout.go
Maybe the line |
because you are using dev mode. In prod mode, there won't be the internal log |
bcf00a2
to
fb87fad
Compare
…ists, omit empty response field
fb87fad
to
c9fd1bb
Compare
@delvh did you have any further reservations? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jolheiser nope.
Ah, nice. With this approval, I've popped the top two priorities off my mental review queue.
Now I can focus on the lower priority PRs again…
res.Err = err.Error() | ||
} | ||
return &res | ||
Err string `json:"err,omitempty"` // server-side error log message, it won't be exposed to end users |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding my previous comment here:
I've previously misunderstood something here, I thought this response would be returned to the user, not that it is the result of a Gitea internal request.
The user message is simply sent through fail
.
That makes a lot more sense then.
* upstream/main: Refactor internal API for git commands, use meaningful messages instead of "Internal Server Error" (go-gitea#23687) Add CSS rules for basic colored labels (go-gitea#23774) Add meilisearch support (go-gitea#23136) Add missing translation for `actions.runners.reset_registration_token_success` (go-gitea#23732) [skip ci] Updated translations via Crowdin Implement Issue Config (go-gitea#20956) Set repository link based on the url in package.json for npm packages (go-gitea#20379) Add API to manage issue dependencies (go-gitea#17935) Add creation time in tag list page (go-gitea#23693) Make minio package support legacy MD5 checksum (go-gitea#23768) Yarden Shoham has a new email address (go-gitea#23767) fix br display for packages curls (go-gitea#23737)
Why this PR comes
At first, I'd like to help users like #23636 (there are a lot)
The unclear "Internal Server Error" is quite anonying, scare users, frustrate contributors, nobody knows what happens.
So, it's always good to provide meaningful messages to end users (of course, do not leak sensitive information).
When I started working on the "response message to end users", I found that the related code has a lot of technical debt. A lot of copy&paste code, unclear fields and usages.
So I think it's good to make everything clear.
Tech Backgrounds
Gitea has many sub-commands, some are used by admins, some are used by SSH servers or Git Hooks. Many sub-commands use "internal API" to communicate with Gitea web server.
Before, Gitea server always use
StatusCode + Json "err" field
to return messages.In the old design, it assumes that:
The old code is not strict, and it's difficult to distinguish the messages clearly and then output them correctly.
This PR
To help to remove duplicate code and make everything clear, this PR introduces
ResponseExtra
andrequestJSONResp
.ResponseExtra
is a struct which contains "extra" information of a internal API response, including StatusCode, UserMsg, ErrorrequestJSONResp
is a generic function which can be used for all cases to help to simplify the calls.map["err"]
, always useprivate.Response{Err}
to construct error messages.fail
andhandleCliResponseExtra
will output correct messages.Internal Server Error
messages with meaningful (still safe) messages.This PR saves more than 300 lines, while makes the git client messages more clear.
Many gitea-serv/git-hook related essential functions are covered by tests.