golang-migrate/migrate · error

expects *AssetSource

Error message

expects *AssetSource

What it means

ErrNoAssetSource is returned by the go-bindata driver's WithInstance when the instance argument is not a *AssetSource. WithInstance requires the caller to pass the driver's own configuration struct; any other value is rejected with this sentinel error.

Source

Thrown at source/go_bindata/go-bindata.go:41

	AssetFunc AssetFunc
}

func init() {
	source.Register("go-bindata", &Bindata{})
}

type Bindata struct {
	path        string
	assetSource *AssetSource
	migrations  *source.Migrations
}

func (b *Bindata) Open(url string) (source.Driver, error) {
	return nil, fmt.Errorf("not yet implemented")
}

var (
	ErrNoAssetSource = fmt.Errorf("expects *AssetSource")
)

func WithInstance(instance interface{}) (source.Driver, error) {
	if _, ok := instance.(*AssetSource); !ok {
		return nil, ErrNoAssetSource
	}
	as := instance.(*AssetSource)

	bn := &Bindata{
		path:        "<go-bindata>",
		assetSource: as,
		migrations:  source.NewMigrations(),
	}

	for _, fi := range as.Names {
		m, err := source.DefaultParse(fi)
		if err != nil {
			continue // ignore files that we can't parse

View on GitHub (pinned to 01a9643f14)

Solutions

  1. Pass an *AssetSource value: bindata.WithInstance(&bindata.AssetSource{Asset: Asset, AssetDir: AssetDir})
  2. Verify you are using the correct bindata package (the one matching your generated assets)
  3. Nil-check the value before passing it so you fail with a clearer message

Example fix

// before
d, err := bindata.WithInstance(Asset)
// after
as := &bindata.AssetSource{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo}
d, err := bindata.WithInstance(as)
Defensive patterns

Strategy: type-guard

Validate before calling

if assetSource == nil {
    return fmt.Errorf("asset source must be non-nil *bindata.AssetSource")
}

Type guard

func asAssetSource(v interface{}) (*bindata.AssetSource, bool) {
    as, ok := v.(*bindata.AssetSource)
    return as, ok && as != nil
}

Try / catch

d, err := bindata.WithInstance(v)
if errors.Is(err, bindata.ErrNoAssetSource) {
    return fmt.Errorf("WithInstance requires *bindata.AssetSource, got %T", v)
}

Prevention

When it happens

Trigger: Calling bindata.WithInstance with nil, a *Bindata, a string, or any type other than &AssetSource{...}.

Common situations: Passing the output of a different driver's WithInstance, passing asset functions (Asset/AssetDir) individually instead of the wrapping struct, or a type mismatch after refactoring imports to a different bindata package.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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