{"record":{"id":"9746a5e5b8329891","repo":"golang-migrate/migrate","slug":"no-database-name-9746a5","errorCode":null,"errorMessage":"no database name","messagePattern":"no database name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"database/sqlite/sqlite.go","lineNumber":26,"sourceCode":"\tnurl \"net/url\"\n\t\"strconv\"\n\t\"strings\"\n\t\"sync/atomic\"\n\n\t\"github.com/golang-migrate/migrate/v4\"\n\t\"github.com/golang-migrate/migrate/v4/database\"\n\t_ \"modernc.org/sqlite\"\n)\n\nfunc init() {\n\tdatabase.Register(\"sqlite\", &Sqlite{})\n}\n\nvar DefaultMigrationsTable = \"schema_migrations\"\nvar (\n\tErrDatabaseDirty  = fmt.Errorf(\"database is dirty\")\n\tErrNilConfig      = fmt.Errorf(\"no config\")\n\tErrNoDatabaseName = fmt.Errorf(\"no database name\")\n)\n\ntype Config struct {\n\tMigrationsTable string\n\tDatabaseName    string\n\tNoTxWrap        bool\n}\n\ntype Sqlite struct {\n\tdb       *sql.DB\n\tisLocked atomic.Bool\n\n\tconfig *Config\n}\n\nfunc WithInstance(instance *sql.DB, config *Config) (database.Driver, error) {\n\tif config == nil {\n\t\treturn nil, ErrNilConfig","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/database/sqlite/sqlite.go#L8-L44","documentation":"ErrNoDatabaseName is a sentinel error returned by the sqlite driver's WithInstance, Open, and WithConnection when Config.DatabaseName (or the URL path) is empty. The driver requires a database name to manage migration state. It indicates the migration URL or config is incomplete.","triggerScenarios":"Calling sqlite.Open(\"sqlite://\") with no path, or WithInstance/WithConnection with a Config whose DatabaseName is \"\" — e.g. a programmatically built URL that lost its path component.","commonSituations":"DSN missing the file path after sqlite://; env var supplying the DB filename empty or unset; URL parsing/cleaning stripping the path; Config struct built without the DatabaseName field.","solutions":["Set Config.DatabaseName or include the path in the URL (sqlite:///path/to/app.db) before constructing the driver.","Validate the database name is non-empty in your config loading and fail fast with a clear message.","Check the deployment environment actually provides the DB filename (env var/config value not empty)."],"exampleFix":"// before\ncfg := &sqlite.Config{} // DatabaseName empty\nd, err := sqlite.WithInstance(db, cfg) // ErrNoDatabaseName\n// after\ncfg := &sqlite.Config{\n    DatabaseName: \"data/app.db\",\n}\nd, err := sqlite.WithInstance(db, cfg)","handlingStrategy":"validation","validationCode":"if cfg == nil || strings.TrimSpace(cfg.DatabaseName) == \"\" {\n    return fmt.Errorf(\"sqlite requires a non-empty DatabaseName\")\n}\n// or for URLs: ensure a path exists\nu, _ := url.Parse(dsn)\nif u.Path == \"\" { return fmt.Errorf(\"migration URL missing database path: %s\", dsn) }","typeGuard":"func hasDatabaseName(cfg *sqlite.Config) bool {\n    return cfg != nil && strings.TrimSpace(cfg.DatabaseName) != \"\"\n}","tryCatchPattern":"if err != nil {\n    if errors.Is(err, sqlite.ErrNoDatabaseName) {\n        return fmt.Errorf(\"check migration DSN/config: database name is required: %w\", err)\n    }\n    return err\n}","preventionTips":["Validate the DSN has a path component before handing it to migrate.","Fail at startup if the env var holding the DB filename is empty.","Keep DSN construction in one tested helper function."],"tags":["sqlite","config","missing-database-name","go"],"backgroundTag":"missing-database-name","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}