golang-migrate/migrate · error

expected *github.Client

Error message

expected *github.Client

What it means

github.ErrInvalidGithubClient is the sentinel returned when a value that is not a *github.Client is supplied where the driver requires one (e.g. constructing/validating the github source driver with an arbitrary client). It is a type assertion failure guard, not a network error.

Source

Thrown at source/github/github.go:27

	"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
}

func (g *Github) Open(url string) (source.Driver, error) {

View on GitHub (pinned to 01a9643f14)

Solutions

  1. Pass a client created by github.NewClient(...) from the same go-github version the driver imports (v39)
  2. If you wrapped the client, wrap inside via github.NewClient(baseHTTPClient) rather than substituting the type
  3. Check import paths for version skew between your code and the migrate driver

Example fix

// before
var c any = myHTTPClient
withInstance(c) // not a *github.Client
// after
client := github.NewClient(myHTTPClient)
withInstance(client) // *github.Client from go-github/v39
Defensive patterns

Strategy: type-guard

Validate before calling

client, ok := c.(*github.Client)
if !ok {
    return fmt.Errorf("need *github.Client from go-github/v39, got %T", c)
}
source.WithInstance(client, cfg)

Type guard

func isGithubClient(v any) bool {
    _, ok := v.(*github.Client)
    return ok
}

Try / catch

d, err := source_github.WithInstance(client, cfg)
if err != nil {
    if errors.Is(err, source_github.ErrInvalidGithubClient) {
        return fmt.Errorf("wrong client type %T; use github.NewClient(...) (go-github/v39)", client)
    }
    return err
}

Prevention

When it happens

Trigger: Passing a *http.Client, a wrapped client, or a differently-versioned go-github client type where *github.Client (go-github/v39) is expected; custom WithInstance wiring that asserts the wrong concrete type.

Common situations: Upgrading go-github major versions (v39 vs another) so the concrete type no longer matches; wrapping the client in middleware that changes its type.

Related errors


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