{"record":{"id":"febf56fd4095bb48","repo":"golang-migrate/migrate","slug":"no-config-febf56","errorCode":null,"errorMessage":"no config","messagePattern":"no config","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"database/cockroachdb/cockroachdb.go","lineNumber":31,"sourceCode":"\n\t\"github.com/cockroachdb/cockroach-go/v2/crdb\"\n\t\"github.com/golang-migrate/migrate/v4\"\n\t\"github.com/golang-migrate/migrate/v4/database\"\n\t\"github.com/lib/pq\"\n)\n\nfunc init() {\n\tdb := CockroachDb{}\n\tdatabase.Register(\"cockroach\", &db)\n\tdatabase.Register(\"cockroachdb\", &db)\n\tdatabase.Register(\"crdb-postgres\", &db)\n}\n\nvar DefaultMigrationsTable = \"schema_migrations\"\nvar DefaultLockTable = \"schema_lock\"\n\nvar (\n\tErrNilConfig      = fmt.Errorf(\"no config\")\n\tErrNoDatabaseName = fmt.Errorf(\"no database name\")\n)\n\ntype Config struct {\n\tMigrationsTable string\n\tLockTable       string\n\tForceLock       bool\n\tDatabaseName    string\n}\n\ntype CockroachDb struct {\n\tdb       *sql.DB\n\tisLocked atomic.Bool\n\n\t// Open and WithInstance need to guarantee that config is never nil\n\tconfig *Config\n}\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/database/cockroachdb/cockroachdb.go#L13-L49","documentation":"The CockroachDB driver defines ErrNilConfig (\"no config\") and returns it from WithInstance, WithConnection, and extractCustomQueryParams when the *Config pointer is nil. Without a config the driver cannot determine migrations table, lock table, or database name, so construction is refused.","triggerScenarios":"Calling cockroachdb.WithInstance(conn, nil), cockroachdb.WithConnection(conn, nil), or extractCustomQueryParams with a nil config.","commonSituations":"Skipping cockroachdb.WithURL / Open and wiring the driver by hand; a nil config returned from an earlier failed parse; uninitialized struct pointer in a DI container.","solutions":["Build the driver via cockroachdb.WithURL(\"cockroachdb://user:pass@host:26257/db?sslmode=disable\") so a populated Config is created.","Or pass a populated &cockroachdb.Config{MigrationsTable: ..., DatabaseName: ...} to WithInstance/WithConnection.","Guard the call site: if cfg == nil { return nil, errors.New(\"cockroachdb config required\") } before invoking the library."],"exampleFix":"// before\nd, err := cockroachdb.WithInstance(db, nil)\n// after\nd, err := cockroachdb.WithURL(\"cockroachdb://root@localhost:26257/migrations?sslmode=disable\")","handlingStrategy":"validation","validationCode":"if cfg == nil {\n    return fmt.Errorf(\"cockroachdb config must not be nil\")\n}\nif cfg.DatabaseName == \"\" {\n    return fmt.Errorf(\"cockroachdb config requires a database name\")\n}","typeGuard":"func validCockroachConfig(cfg *cockroachdb.Config) bool {\n    return cfg != nil && cfg.DatabaseName != \"\"\n}","tryCatchPattern":"d, err := cockroachdb.WithInstance(db, cfg)\nif err != nil {\n    if errors.Is(err, cockroachdb.ErrNilConfig) {\n        return fmt.Errorf(\"use cockroachdb.WithURL or pass a populated *cockroachdb.Config\")\n    }\n    return err\n}","preventionTips":["Use cockroachdb.WithURL to derive the Config from a DSN instead of constructing drivers by hand.","Never pass nil for *Config; centralize driver creation in one factory function.","Test the driver-construction helper for nil-input behavior."],"tags":["cockroachdb","configuration","nil-config"],"backgroundTag":"nil-config","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}