golang-migrate/migrate · error
no config
Error message
no config
What it means
The ClickHouse driver defines ErrNilConfig ("no config") and returns it from WithInstance, WithConnection, and extractCustomQueryParams when the *Config argument is nil. It signals that driver construction was attempted without any configuration object, so there is nothing to read database name, table, or engine settings from.
Source
Thrown at database/clickhouse/clickhouse.go:26
"net/url"
"strconv"
"strings"
"sync/atomic"
"time"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database"
"github.com/golang-migrate/migrate/v4/database/multistmt"
)
var (
multiStmtDelimiter = []byte(";")
DefaultMigrationsTable = "schema_migrations"
DefaultMigrationsTableEngine = "TinyLog"
DefaultMultiStatementMaxSize = 10 * 1 << 20 // 10 MB
ErrNilConfig = fmt.Errorf("no config")
)
type Config struct {
DatabaseName string
ClusterName string
MigrationsTable string
MigrationsTableEngine string
MultiStatementEnabled bool
MultiStatementMaxSize int
}
func init() {
database.Register("clickhouse", &ClickHouse{})
}
func WithInstance(conn *sql.DB, config *Config) (database.Driver, error) {
if config == nil {
return nil, ErrNilConfigView on GitHub (pinned to 01a9643f14)
Solutions
- Construct a config first: use clickhouse.WithURL(dsn) which parses the DSN into a Config, or build &Config{...} manually and pass it to WithInstance.
- Check for nil before calling WithInstance/WithConnection and return your own descriptive error.
- Ensure the code path that was supposed to initialize the config actually ran (no early returns skipping initialization).
Example fix
// before
ch, err := clickhouse.WithInstance(conn, nil)
// after
cfg := &clickhouse.Config{DatabaseName: "default", MigrationsTable: clickhouse.DefaultMigrationsTable}
ch, err := clickhouse.WithInstance(conn, cfg) Defensive patterns
Strategy: validation
Validate before calling
if cfg == nil {
return fmt.Errorf("clickhouse config must not be nil")
} Type guard
func validClickhouseConfig(cfg *clickhouse.Config) bool {
return cfg != nil && cfg.MigrationsTable != ""
} Try / catch
ch, err := clickhouse.WithInstance(conn, cfg)
if err != nil {
if errors.Is(err, clickhouse.ErrNilConfig) {
return fmt.Errorf("clickhouse driver requires a config; use clickhouse.WithURL")
}
return err
} Prevention
- Prefer clickhouse.WithURL(dsn) so the Config is always populated by the library.
- If building Config manually, initialize it in one constructor and never pass bare nil.
- Add a nil-check assertion in tests for every driver construction path.
When it happens
Trigger: Passing nil as the config to clickhouse.WithInstance(conn, nil) or clickhouse.WithConnection(conn, nil); calling extractCustomQueryParams with a nil config.
Common situations: Building a driver programmatically without calling clickhouse.Config or WithURL first; a config variable that was declared but never initialized; an early-return path that lost the config value.
Related errors
AI-assisted analysis of golang-migrate/migrate@01a9643f14 (2026-09-02).
Data as JSON: /api/errors/9f53696915f18573.
Report an issue: GitHub.