golang-migrate/migrate · error

no config

Error message

no config

What it means

ErrNilConfig is returned by the Cassandra driver's WithInstance and WithConnection constructors when the *Config argument is nil. The driver requires a Config (at minimum KeyspaceName) to operate, and dereferencing a nil config would panic, so the library fails fast with this sentinel error. It signals a programming mistake by the caller, not a runtime/database failure.

Source

Thrown at database/cassandra/cassandra.go:32

	"github.com/golang-migrate/migrate/v4/database"
	"github.com/golang-migrate/migrate/v4/database/multistmt"
)

func init() {
	db := new(Cassandra)
	database.Register("cassandra", db)
}

var (
	multiStmtDelimiter = []byte(";")

	DefaultMultiStatementMaxSize = 10 * 1 << 20 // 10 MB
)

var DefaultMigrationsTable = "schema_migrations"

var (
	ErrNilConfig     = errors.New("no config")
	ErrNoKeyspace    = errors.New("no keyspace provided")
	ErrDatabaseDirty = errors.New("database is dirty")
	ErrClosedSession = errors.New("session is closed")
)

type Config struct {
	MigrationsTable       string
	KeyspaceName          string
	MultiStatementEnabled bool
	MultiStatementMaxSize int
}

type Cassandra struct {
	session  *gocql.Session
	isLocked atomic.Bool

	// Open and WithInstance need to guarantee that config is never nil
	config *Config

View on GitHub (pinned to 01a9643f14)

Solutions

  1. Pass a non-nil *cassandra.Config (set KeyspaceName at minimum) to WithInstance/WithConnection.
  2. Open via the connection URL 'cassandra://host:9042/keyspace' so the driver parses and builds the config for you.
  3. Check for nil config in your own wrapper before calling the driver and fail with a clearer message.

Example fix

// before
driver, err := cassandra.WithInstance(session, nil)
// after
cfg := &cassandra.Config{KeyspaceName: "my_keyspace"}
driver, err := cassandra.WithInstance(session, cfg)
Defensive patterns

Strategy: validation

Validate before calling

if config == nil {
    return fmt.Errorf("cassandra driver requires a non-nil *cassandra.Config")
}

Type guard

func hasConfig(cfg *cassandra.Config) bool { return cfg != nil }

Try / catch

driver, err := cassandra.WithInstance(session, cfg)
if err != nil {
    if errors.Is(err, cassandra.ErrNilConfig) {
        return fmt.Errorf("driver setup: config was not provided: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling database/cassandra WithInstance(session, nil) or WithConnection(conn, nil); also building a driver programmatically and forgetting to populate the config struct (empty or zero-value pointer passed in).

Common situations: Constructing the driver in code without a config file (e.g. omitting the 'x-migrations-table' style config or the cassandra:// URL query params), refactorings where a Config variable became nil, or test harnesses that pass nil placeholders.

Related errors


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