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

GetFileMetaData errors on missing file #1047

Closed
Pie4kaiz opened this issue Jan 25, 2021 · 0 comments · Fixed by #1919
Closed

GetFileMetaData errors on missing file #1047

Pie4kaiz opened this issue Jan 25, 2021 · 0 comments · Fixed by #1919
Labels

Comments

@Pie4kaiz
Copy link

Pie4kaiz commented Jan 25, 2021

When calling the RepositoryFilesService.GetFileMetaData() function on a file that doesn't exist, but the request was successful, I expect the returned *File and error to be nil.
Instead I get an ErrorResponse containing HEAD http://127.0.0.1:49996/api/v4/projects/1234/repository/files/foobar.yaml: 404 failed to parse unknown error format.

This is due to the fact that CheckResponse() (called by Client.Do(), called by RepositoryFilesService.GetFileMetaData()) tries to parse the empty body as JSON.
I think it fails here:

data, err := ioutil.ReadAll(r.Body)
	if err == nil && data != nil {

data doesn't seem to be nil here, maybe it contains \r\n? As I can see, this endpoint that came with #511 is the only one within the codebase using HEAD, which is probably why it never popped up before.
Nevertheless I think that a HEAD request that returns 404 should either be not an error or some specific error (e.g. NotFoundError) to be catchable.

svanharmelen added a commit to vntw/go-gitlab that referenced this issue Apr 19, 2024
svanharmelen added a commit to vntw/go-gitlab that referenced this issue Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants