golang-migrate/migrate · error

no username:password provided

Error message

no username:password provided

What it means

ErrNoUserInfo is returned by the bitbucket source driver's Open when the source URL contains no user info component. The driver builds a basic-auth Bitbucket client from the URL, so it requires a username in the URL. It is an exported sentinel error comparable with errors.Is.

Source

Thrown at source/bitbucket/bitbucket.go:21

import (
	"fmt"
	"io"
	nurl "net/url"
	"os"
	"path"
	"path/filepath"
	"strings"

	"github.com/golang-migrate/migrate/v4/source"
	"github.com/ktrysmt/go-bitbucket"
)

func init() {
	source.Register("bitbucket", &Bitbucket{})
}

var (
	ErrNoUserInfo             = fmt.Errorf("no username:password provided")
	ErrNoAccessToken          = fmt.Errorf("no password/app password")
	ErrInvalidRepo            = fmt.Errorf("invalid repo")
	ErrInvalidBitbucketClient = fmt.Errorf("expected *bitbucket.Client")
	ErrNoDir                  = fmt.Errorf("no directory")
)

type Bitbucket struct {
	config     *Config
	client     *bitbucket.Client
	migrations *source.Migrations
}

type Config struct {
	Owner string
	Repo  string
	Path  string
	Ref   string
}

View on GitHub (pinned to 01a9643f14)

Solutions

  1. Include a username (and password) in the URL: `bitbucket://username:app-password@owner/repo/migrations#branch`.
  2. Verify the URL string in your config/scripts actually contains `user:pass@` after env substitution.
  3. Use an app password (Bitbucket requires basic auth), not your account password or an OAuth token, in the password slot.
  4. Compare with errors.Is(err, bitbucket.ErrNoUserInfo) in code to give a clear config error to users.

Example fix

// before
url := "bitbucket://myteam/myrepo/migrations#master"
// after
url := "bitbucket://myuser:my-app-password@myteam/myrepo/migrations#master"
Defensive patterns

Strategy: validation

Validate before calling

u, err := nurl.Parse(sourceURL)
if err != nil {
    return err
}
if u.Scheme == "bitbucket" && u.User == nil {
    return fmt.Errorf("bitbucket source URL requires user:password, got %q", sourceURL)
}

Type guard

func hasURLUserInfo(u *nurl.URL) bool {
    return u != nil && u.User != nil && u.User.Username() != ""
}

Try / catch

d, err := bitbucket.Open(url)
if errors.Is(err, bitbucket.ErrNoUserInfo) {
    return fmt.Errorf("bitbucket source needs basic auth in URL: bitbucket://user:app-password@owner/repo#ref")
}

Prevention

When it happens

Trigger: Opening a bitbucket source URL without credentials, e.g. `bitbucket://owner/repo/path#ref` or `bitbucket://owner@host/...` with no `:password`, so u.User is nil after url.Parse.

Common situations: Forgetting to embed credentials in the source URL in migrate config; removing the password for 'security' but leaving out the username too; URL built programmatically without user info; env-substituted URL where credentials vars were empty.

Related errors


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