Incorrect URL in error messages
bradleyjames opened this issue · comments
I've spent a good amount of time recently trying to debug issues in goreleaser which uses go-gitlab. What I've found is that error messages go-gitlab returns include URLs which are not the URL that is being invoked. The URL is being unescaped when it shouldn't in go-gitlab's error handling code. This makes debugging difficult as it's sent me down the wrong path multiple times because the calls aren't valid.
Here's a test I'm using. The referenced repos are private and not available to anyone outside our organization. The fileName is an invalid path.
package main
import (
"fmt"
"os"
"github.com/xanzy/go-gitlab"
)
func main() {
accessToken := os.Getenv("GITLAB_TOKEN")
glClient, _ := gitlab.NewClient(accessToken)
projectID := "shipium-corp/engineering/homebrew-shipium"
ref := "main"
fileName := "Formula/invalid.r"
opts := &gitlab.GetFileOptions{Ref: &ref}
f, _, err := glClient.RepositoryFiles.GetFile(projectID, fileName, opts)
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
}
fmt.Printf("File: %v\n", f)
}
The error that is printed is:
GET https://gitlab.com/api/v4/projects/shipium-corp/engineering/homebrew-shipium/repository/files/Formula/invalid.r: 404 {message: 404 File Not Found}
The actual URL invoked is https://gitlab.com/api/v4/projects/shipium-corp%2Fengineering%2Fhomebrew-shipium/repository/files/Formula%2Finvalid%2Er
. The issue is the URL unescaping performed by the error handling code when building the error message. The repository name and the file name must be URL encoded to be valid when invoking gitlab's REST API.
The problematic line is the following at
Line 953 in 8f2dbc2
I believe this should be the following instead:
path := e.Response.Request.URL.RawPath
With this update, the error include the appropriate URL in the error message.
GET https://gitlab.com/api/v4/projects/shipium-corp%2Fengineering%2Fhomebrew-sh ipium/repository/files/Formula%2Finvalid%2Er: 404 {message: 404 File Not Found}
There is still a remaining issue in that the query params are not appended. I haven't tackled that yet but I assume the solution is on the same path as what I included above.