golang-migrate/migrate · error
no username:token provided
Error message
no username:token provided
What it means
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>@...
Source
Thrown at source/gitlab/gitlab.go:24
"io"
"net/http"
nurl "net/url"
"os"
"strconv"
"strings"
"github.com/golang-migrate/migrate/v4/source"
"github.com/xanzy/go-gitlab"
)
func init() {
source.Register("gitlab", &Gitlab{})
}
const DefaultMaxItemsPerPage = 100
var (
ErrNoUserInfo = fmt.Errorf("no username:token provided")
ErrNoAccessToken = fmt.Errorf("no access token")
ErrInvalidHost = fmt.Errorf("invalid host")
ErrInvalidProjectID = fmt.Errorf("invalid project id")
ErrInvalidResponse = fmt.Errorf("invalid response")
)
type Gitlab struct {
client *gitlab.Client
url string
projectID string
path string
listOptions *gitlab.ListTreeOptions
getOptions *gitlab.GetFileOptions
migrations *source.Migrations
}
type Config struct {View on GitHub (pinned to 01a9643f14)
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
Example fix
// before
source.Open("gitlab://gitlab.com/group/project/migrations")
// after
source.Open("gitlab://deploy:glpat-xxx@gitlab.com/group/project/migrations") Defensive patterns
Strategy: validation
Validate before calling
u, err := url.Parse(sourceURL)
if err != nil {
return err
}
if u.Scheme == "gitlab" && u.User == nil {
return fmt.Errorf("gitlab source url requires user:token credentials")
} Type guard
func hasGitlabCreds(raw string) bool {
u, err := url.Parse(raw)
if err != nil || u.Scheme != "gitlab" {
return false
}
return u.User != nil
} Try / catch
d, err := source_gitlab.Open(srcURL)
if err != nil {
if errors.Is(err, source_gitlab.ErrNoUserInfo) {
return fmt.Errorf("gitlab source url must include user:token")
}
return err
} Prevention
- 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
When it happens
Trigger: Open('gitlab://gitlab.com/group/project/path') with no user:token component at all, so u.User == nil and Open returns ErrNoUserInfo.
Common situations: 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://.
Related errors
- no username:password provided
- no username:token provided
- no access token
- invalid host
- invalid project id
AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02).
Data as JSON: /api/errors/f9af467dacf9d739.
Report an issue: GitHub.