golang-migrate/migrate · error

no config

Error message

no config

What it means

ErrNilConfig is a sentinel error returned by the sqlcipher driver's WithInstance and WithConnection when the *Config argument passed in is nil. The driver requires a Config (at minimum a database name / migrations table) to construct the Driver. It is a programming error, not a runtime condition.

Source

Thrown at database/sqlcipher/sqlcipher.go:25

	"io"
	nurl "net/url"
	"strconv"
	"strings"
	"sync/atomic"

	"github.com/golang-migrate/migrate/v4"
	"github.com/golang-migrate/migrate/v4/database"
	_ "github.com/mutecomm/go-sqlcipher/v4"
)

func init() {
	database.Register("sqlcipher", &Sqlite{})
}

var DefaultMigrationsTable = "schema_migrations"
var (
	ErrDatabaseDirty  = fmt.Errorf("database is dirty")
	ErrNilConfig      = fmt.Errorf("no config")
	ErrNoDatabaseName = fmt.Errorf("no database name")
)

type Config struct {
	MigrationsTable string
	DatabaseName    string
	NoTxWrap        bool
}

type Sqlite struct {
	db       *sql.DB
	isLocked atomic.Bool

	config *Config
}

func WithInstance(instance *sql.DB, config *Config) (database.Driver, error) {
	if config == nil {

View on GitHub (pinned to 01a9643f14)

Solutions

  1. Pass a non-nil *sqlcipher.Config to WithInstance/WithConnection, e.g. &sqlcipher.Config{DatabaseName: "mydb", MigrationsTable: sqlcipher.DefaultMigrationsTable}.
  2. If config is built from env/file, validate it is non-nil before calling the driver constructor.
  3. Use migrate.New/sourcefile://... or Open with a URL instead, which builds the config internally.

Example fix

// before
d, err := sqlcipher.WithInstance(db, nil)
// after
cfg := &sqlcipher.Config{
    DatabaseName:    "app",
    MigrationsTable: sqlcipher.DefaultMigrationsTable,
}
d, err := sqlcipher.WithInstance(db, cfg)
Defensive patterns

Strategy: validation

Validate before calling

if cfg == nil {
    return fmt.Errorf("sqlcipher config must not be nil")
}

Type guard

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

Try / catch

d, err := sqlcipher.WithInstance(db, cfg)
if err != nil {
    if errors.Is(err, sqlcipher.ErrNilConfig) {
        return fmt.Errorf("programming error: pass a *sqlcipher.Config: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling sqlcipher.WithInstance(db, nil) or sqlcipher.WithConnection(conn, nil) — passing a nil *Config pointer directly to the driver constructor.

Common situations: Copy-pasted driver setup code where the Config struct literal was deleted or commented out; building config conditionally and the nil branch being reached; wiring frameworks (DI) that inject a nil config when a config file/env was missing.

Related errors


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