golang-migrate/migrate · error

no access token

Error message

no access token

What it means

gitlab.ErrNoAccessToken is the GitLab driver's sentinel for a missing access token — the token (password part of the URL userinfo) required to call the GitLab API. Returned by Gitlab.Open when the token component is absent.

Source

Thrown at source/gitlab/gitlab.go:25

	"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

  1. Append the token to the userinfo: 'gitlab://user:<token>@gitlab.com/...'
  2. Verify the secret/env value injecting the token is populated
  3. Create a new PAT with api or read_api/read_repository scope if the old one was revoked

Example fix

// before
source.Open("gitlab://deploy@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" {
    pw, ok := u.User.Password()
    if !ok || pw == "" {
        return fmt.Errorf("gitlab source url missing access token after ':' in userinfo")
    }
}

Type guard

func hasGitlabToken(raw string) bool {
    u, err := url.Parse(raw)
    if err != nil || u.User == nil {
        return false
    }
    pw, ok := u.User.Password()
    return ok && pw != ""
}

Try / catch

d, err := source_gitlab.Open(srcURL)
if err != nil {
    if errors.Is(err, source_gitlab.ErrNoAccessToken) {
        return fmt.Errorf("add token as password part: gitlab://user:token@gitlab.com/...")
    }
    return err
}

Prevention

When it happens

Trigger: Open('gitlab://user@gitlab.com/group/project') — username present but no ':token' — so no access token can be extracted; or empty password after templating ('user:@host').

Common situations: Rotated or revoked PATs removed from config; secret managers returning empty strings; docs examples copied without the token segment.

Related errors


AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02). Data as JSON: /api/errors/b2eb08c0836c17ae. Report an issue: GitHub.