golang-migrate/migrate · error
no access token
Error message
no access token
What it means
github.ErrNoAccessToken is declared in source/github/github.go as the companion credential error for the GitHub driver; it signals that no access token was supplied for authenticated access. The analogous bitbucket driver returns it when the URL userinfo has a username but no password (app password).
Source
Thrown at source/github/github.go:25
"net/http"
nurl "net/url"
"os"
"path"
"strings"
"golang.org/x/oauth2"
"github.com/golang-migrate/migrate/v4/source"
"github.com/google/go-github/v39/github"
)
func init() {
source.Register("github", &Github{})
}
var (
ErrNoUserInfo = fmt.Errorf("no username:token provided")
ErrNoAccessToken = fmt.Errorf("no access token")
ErrInvalidRepo = fmt.Errorf("invalid repo")
ErrInvalidGithubClient = fmt.Errorf("expected *github.Client")
ErrNoDir = fmt.Errorf("no directory")
)
type Github struct {
config *Config
client *github.Client
options *github.RepositoryContentGetOptions
migrations *source.Migrations
}
type Config struct {
Owner string
Repo string
Path string
Ref string
}View on GitHub (pinned to 01a9643f14)
Solutions
- Supply the token/app-password in the URL: scheme://user:token@host/...
- Verify the token env var is set and non-empty before building the URL
- Use the driver's WithInstance constructor with an authenticated API client instead
Example fix
// before
source.Open("bitbucket://myuser@bitbucket.org/workspace/repo/migrations")
// after
source.Open("bitbucket://myuser:app-password@bitbucket.org/workspace/repo/migrations") Defensive patterns
Strategy: validation
Validate before calling
if accessToken == "" {
return fmt.Errorf("access token env var must be set before building source url")
}
sourceURL := fmt.Sprintf("bitbucket://user:%s@bitbucket.org/ws/repo/migrations", accessToken) Type guard
func hasAccessToken(raw string) bool {
u, err := url.Parse(raw)
if err == nil && u.User != nil {
pw, ok := u.User.Password()
return ok && pw != ""
}
return true // no userinfo: some drivers allow unauthenticated
} Try / catch
d, err := src.Open(srcURL)
if err != nil {
if errors.Is(err, ErrNoAccessToken) {
return fmt.Errorf("supply token as password part of source URL")
}
return err
} Prevention
- Fail fast at startup when the token env var is empty
- Rotate tokens via secret manager with a non-empty check
- For private repos, never rely on unauthenticated access
When it happens
Trigger: In bitbucket: Open('bitbucket://user@bitbucket.org/...') where u.User.Password() fails. In github: declared at source/github/github.go:25 as the token-missing sentinel returned from Open paths lacking a token.
Common situations: Env-injected token missing or empty so the URL renders as 'user:@host'; rotating tokens and forgetting to update the DSN; private repos requiring auth while no token was configured.
Related errors
- no username:password provided
- no password/app password
- no username:token provided
- no access token
- no password
AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02).
Data as JSON: /api/errors/0d2ac8da237b32ac.
Report an issue: GitHub.