{"record":{"id":"358979f7b42a1916","repo":"benbjohnson/litestream","slug":"failed-to-create-db-for-s-w","errorCode":null,"errorMessage":"failed to create DB for %s: %w","messagePattern":"failed to create DB for (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/main.go","lineNumber":849,"sourceCode":"\n\t// Find all SQLite databases in the directory\n\tdbPaths, err := FindSQLiteDatabases(dirPath, dbc.Pattern, dbc.Recursive)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to scan directory %s: %w\", dirPath, err)\n\t}\n\n\tif len(dbPaths) == 0 && !dbc.Watch {\n\t\treturn nil, fmt.Errorf(\"no SQLite databases found in directory %s with pattern %s\", dirPath, dbc.Pattern)\n\t}\n\n\t// Create DB instances for each found database\n\tvar dbs []*litestream.DB\n\tmetaPaths := make(map[string]string)\n\n\tfor _, dbPath := range dbPaths {\n\t\tdb, err := newDBFromDirectoryEntry(dbc, dirPath, dbPath)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to create DB for %s: %w\", dbPath, err)\n\t\t}\n\n\t\t// Validate unique meta-path to prevent replication state corruption\n\t\tif mp := db.MetaPath(); mp != \"\" {\n\t\t\tif existingDB, exists := metaPaths[mp]; exists {\n\t\t\t\treturn nil, fmt.Errorf(\"meta-path collision: databases %s and %s would share meta-path %s, causing replication state corruption\", existingDB, dbPath, mp)\n\t\t\t}\n\t\t\tmetaPaths[mp] = dbPath\n\t\t}\n\n\t\tdbs = append(dbs, db)\n\t}\n\n\treturn dbs, nil\n}\n\n// newDBFromDirectoryEntry creates a DB instance for a database discovered via directory replication.\nfunc newDBFromDirectoryEntry(dbc *DBConfig, dirPath, dbPath string) (*litestream.DB, error) {","sourceCodeStart":831,"sourceCodeEnd":867,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/main.go#L831-L867","documentation":"For each discovered database, newDBFromDirectoryEntry builds a per-DB litestream.DB. If constructing any individual DB fails (bad path, invalid replica config, etc.), the error is wrapped with the offending database path so the misconfigured entry is identifiable.","triggerScenarios":"newDBFromDirectoryEntry(dbc, dirPath, dbPath) returns an error for a specific dbPath — including any of errors 106/107/108/109 or failures inside litestream.NewDB (e.g. unwritable meta path).","commonSituations":"One database file in the scanned directory has a pathological name (unusual characters breaking path/URL derivation); replica URL invalid; meta directory not creatable for one entry; a file matches the glob but is not a real SQLite database.","solutions":["Look at the wrapped inner error and the %s path in the message to find the specific failing database.","Fix the underlying issue for that file (rename it, fix its derived meta path, correct the replica config).","Narrow the pattern to exclude files that should not be treated as databases.","Test the same config against a single-DB stanza for that path to isolate the failure."],"exampleFix":"# before\npattern: \"**/*\"  # matches logs, temp files, everything\n\n# after\npattern: \"**/*.db\"  # only real database files","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"dbs, err := NewDBsFromDirectoryConfig(dbc)\nif err != nil {\n    var e *fmt.WrapError // inspect message for \"failed to create DB for <path>\"\n    log.Fatalf(\"directory replication setup failed: %v\", err)\n}","preventionTips":["Keep database filenames simple (ASCII, no spaces) for directory replication.","Narrow the pattern so only real SQLite files match.","Validate the replica config independently before enabling directory mode."],"tags":["litestream","directory-replication","initialization"],"backgroundTag":"invalid-config-value","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}