{"record":{"id":"f9af467dacf9d739","repo":"golang-migrate/migrate","slug":"no-username-token-provided-f9af46","errorCode":null,"errorMessage":"no username:token provided","messagePattern":"no username:token provided","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"source/gitlab/gitlab.go","lineNumber":24,"sourceCode":"\t\"io\"\n\t\"net/http\"\n\tnurl \"net/url\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/golang-migrate/migrate/v4/source\"\n\t\"github.com/xanzy/go-gitlab\"\n)\n\nfunc init() {\n\tsource.Register(\"gitlab\", &Gitlab{})\n}\n\nconst DefaultMaxItemsPerPage = 100\n\nvar (\n\tErrNoUserInfo       = fmt.Errorf(\"no username:token provided\")\n\tErrNoAccessToken    = fmt.Errorf(\"no access token\")\n\tErrInvalidHost      = fmt.Errorf(\"invalid host\")\n\tErrInvalidProjectID = fmt.Errorf(\"invalid project id\")\n\tErrInvalidResponse  = fmt.Errorf(\"invalid response\")\n)\n\ntype Gitlab struct {\n\tclient *gitlab.Client\n\turl    string\n\n\tprojectID   string\n\tpath        string\n\tlistOptions *gitlab.ListTreeOptions\n\tgetOptions  *gitlab.GetFileOptions\n\tmigrations  *source.Migrations\n}\n\ntype Config struct {","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/source/gitlab/gitlab.go#L6-L42","documentation":"Sentinel error ErrNoUserInfo defined in source/gitlab/gitlab.go. It fires when the gitlab:// source URL has no user info component, meaning no username:token pair was provided for GitLab API authentication. The same pattern is used in source/bitbucket, where Open returns ErrNoUserInfo when u.User is nil. Fix by embedding a username and access token in the URL, e.g. gitlab://<user>:<token>@...","triggerScenarios":"Open('gitlab://gitlab.com/group/project/path') with no user:token component at all, so u.User == nil and Open returns ErrNoUserInfo.","commonSituations":"Assuming gitlab:// works unauthenticated; CI pipelines where the GITLAB token env var was empty so the userinfo section was dropped by templating; moving from github:// (token optional for public repos) to gitlab://.","solutions":["Add credentials to the URL: 'gitlab://<user>:<personal-access-token>@gitlab.com/group/project'","Check the token env var is non-empty before composing the URL","Consider using an OAuth/project access token with read_repository scope"],"exampleFix":"// before\nsource.Open(\"gitlab://gitlab.com/group/project/migrations\")\n// after\nsource.Open(\"gitlab://deploy:glpat-xxx@gitlab.com/group/project/migrations\")","handlingStrategy":"validation","validationCode":"u, err := url.Parse(sourceURL)\nif err != nil {\n    return err\n}\nif u.Scheme == \"gitlab\" && u.User == nil {\n    return fmt.Errorf(\"gitlab source url requires user:token credentials\")\n}","typeGuard":"func hasGitlabCreds(raw string) bool {\n    u, err := url.Parse(raw)\n    if err != nil || u.Scheme != \"gitlab\" {\n        return false\n    }\n    return u.User != nil\n}","tryCatchPattern":"d, err := source_gitlab.Open(srcURL)\nif err != nil {\n    if errors.Is(err, source_gitlab.ErrNoUserInfo) {\n        return fmt.Errorf(\"gitlab source url must include user:token\")\n    }\n    return err\n}","preventionTips":["Always include user:token in gitlab:// URLs — unlike github, creds are required","Check token env vars before URL templating in CI","Use a project/deploy token with read_repository scope"],"tags":["gitlab","authentication","url"],"backgroundTag":"missing-credentials","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}