{"record":{"id":"eb960c21bd43c165","repo":"golang-migrate/migrate","slug":"no-config-eb960c","errorCode":null,"errorMessage":"no config","messagePattern":"no config","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"database/postgres/postgres.go","lineNumber":38,"sourceCode":"\t\"github.com/golang-migrate/migrate/v4/database/multistmt\"\n\t\"github.com/lib/pq\"\n)\n\nfunc init() {\n\tdb := Postgres{}\n\tdatabase.Register(\"postgres\", &db)\n\tdatabase.Register(\"postgresql\", &db)\n}\n\nvar (\n\tmultiStmtDelimiter = []byte(\";\")\n\n\tDefaultMigrationsTable       = \"schema_migrations\"\n\tDefaultMultiStatementMaxSize = 10 * 1 << 20 // 10 MB\n)\n\nvar (\n\tErrNilConfig      = fmt.Errorf(\"no config\")\n\tErrNoDatabaseName = fmt.Errorf(\"no database name\")\n\tErrNoSchema       = fmt.Errorf(\"no schema\")\n\tErrDatabaseDirty  = fmt.Errorf(\"database is dirty\")\n)\n\ntype Config struct {\n\tMigrationsTable       string\n\tMigrationsTableQuoted bool\n\tMultiStatementEnabled bool\n\tDatabaseName          string\n\tSchemaName            string\n\tmigrationsSchemaName  string\n\tmigrationsTableName   string\n\tStatementTimeout      time.Duration\n\tMultiStatementMaxSize int\n}\n\ntype Postgres struct {","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/database/postgres/postgres.go#L20-L56","documentation":"ErrNilConfig is the sentinel error database/postgres (and copies in cassandra, pgx, cockroachdb, etc.) returns from WithInstance/WithConnection/Open when the *Config argument is nil. It signals a programming mistake: the driver was invoked without required configuration. Compare with errors.Is(err, postgres.ErrNilConfig).","triggerScenarios":"Calling postgres.WithInstance(conn, nil) or postgres.WithConnection(conn, nil); passing a nil *Config from a wrapper; the cassandra/pgx variants likewise return their local ErrNilConfig when config == nil.","commonSituations":"Constructing the driver manually instead of via URL-driven Open and forgetting to build a Config struct; reflection-based or DI wiring that yields a nil pointer; refactors that made Config optional in a caller's eyes.","solutions":["Always pass a non-nil *postgres.Config (at minimum set DatabaseName or let Open derive it from the URL)","Check errors.Is(err, postgres.ErrNilConfig) to branch on this specific case","If config comes from another function, nil-check it before calling WithInstance/WithConnection"],"exampleFix":"// before\ndriver, err := postgres.WithInstance(conn, nil)\n// after\ncfg := &postgres.Config{DatabaseName: \"mydb\"}\ndriver, err := postgres.WithInstance(conn, cfg)","handlingStrategy":"validation","validationCode":"if cfg == nil {\n    return nil, errors.New(\"postgres config is required\")\n}\ndriver, err := postgres.WithInstance(conn, cfg)","typeGuard":"func configProvided(cfg *postgres.Config) bool { return cfg != nil }","tryCatchPattern":"if err != nil {\n    if errors.Is(err, postgres.ErrNilConfig) {\n        log.Fatal(\"a *postgres.Config must be passed to WithInstance/WithConnection\")\n    }\n    panic(err)\n}","preventionTips":["Never pass nil for *Config; build at least an empty &postgres.Config{} with required fields","Nil-check configuration structs constructed from env vars before use","Use errors.Is against exported sentinels (ErrNilConfig, ErrNoDatabaseName) for precise handling"],"tags":["nil-config","programming-error","postgres","sentinel-error"],"backgroundTag":"nil-config-argument","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}