-
-
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
Handle invalid target when creating releases using API #31841
Conversation
|
@@ -65,7 +65,7 @@ func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Rel | |||
|
|||
commit, err := gitRepo.GetCommit(rel.Target) | |||
if err != nil { | |||
return false, fmt.Errorf("createTag::GetCommit[%v]: %w", rel.Target, err) |
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.
Why remove the more verbose error message?
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.
I removed it as createTag
and GetCommit
seemed too implementation-specific to release_service.CreateRelease()
for it to be included in the API route. I have added an alternative message before printing out the error; let me know if it can be improved!
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.
The functions in services will be used by both web side and API.
So if you want to change it for API, it is better to also check the web side.
ps: the alternative message you added is in this PR? L256 in routers/api/v1/repo/release.go?
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.
So if you want to change it for API, it is better to also check the web side.
From reading the web route code and observing the web UI, it doesn't seem possible for normal users to pass an invalid target (unless they make create the HTTP request by hand and send it, then they'll get a server error code).
ps: the alternative message you added is in this PR? L256 in routers/api/v1/repo/release.go?
Yes that is correct. I'm open for better ways of describing the error.
Did not read the Mozilla docs for this closely (they explain that is used for "implementation specific purposes"). I think either a 404 or 422 makes sense here; I opted for 404. |
Tag names cannot have spaces.
* giteaofficial/main: Handle invalid target when creating releases using API (go-gitea#31841)
A 500 status code was thrown when passing a non-existent target to the create release API. This snapshot handles this error and instead throws a 404 status code. Discovered while working on go-gitea#31840.
A 500 status code was thrown when passing a non-existent target to the create release API. This snapshot handles this error and instead throws a 404 status code.
Discovered while working on #31840.