golang-migrate/migrate · error

expected *bitbucket.Client

Error message

expected *bitbucket.Client

What it means

ErrInvalidBitbucketClient is the sentinel error the bitbucket source driver uses when WithInstance (or New) receives a client argument that is not a *bitbucket.Client from github.com/ktrysmt/go-bitbucket. It is an exported error used for type-assertion failures on the driver's internal client field.

Source

Thrown at source/bitbucket/bitbucket.go:24

	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
}

func (b *Bitbucket) Open(url string) (source.Driver, error) {
	u, err := nurl.Parse(url)

View on GitHub (pinned to 01a9643f14)

Solutions

  1. Create the client with bitbucket.NewBasicAuth(username, appPassword) from go-bitbucket and pass that to WithInstance.
  2. Check for a nil client before calling WithInstance.
  3. Update imports to use github.com/ktrysmt/go-bitbucket's Client type if you migrated from another library.
  4. In tests, use the same concrete type or an interface seam instead of a mismatched stub.

Example fix

// before
b.WithInstance(someHTTPClient, cfg)
// after
cl := bitbucket.NewBasicAuth(user, pass)
b.WithInstance(cl, cfg)
Defensive patterns

Strategy: type-guard

Validate before calling

if cl == nil {
    return fmt.Errorf("bitbucket client must be created via bitbucket.NewBasicAuth(user, appPassword)")
}
if _, ok := interface{}(cl).(*bitbucket.Client); !ok {
    return fmt.Errorf("wrong client type %T", cl)
}

Type guard

func isBitbucketClient(c interface{}) bool {
    _, ok := c.(*bitbucket.Client)
    return ok
}

Try / catch

d, err := bitbucket.WithInstance(cl, cfg)
if errors.Is(err, bitbucket.ErrInvalidBitbucketClient) {
    return fmt.Errorf("pass *bitbucket.Client from go-bitbucket, got %T", cl)
}

Prevention

When it happens

Trigger: Calling bitbucket.WithInstance with a nil or wrongly-typed client, or constructing the driver so its client field holds something other than *bitbucket.Client; typically a programming error, not a runtime/config error.

Common situations: Passing a custom HTTP client wrapper instead of *bitbucket.Client; nil client after a failed constructor; refactoring that changed the client type; tests stubbing the client with the wrong type.

Related errors


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