{"record":{"id":"d00c2d0c9589b625","repo":"benbjohnson/litestream","slug":"database-config-d-pattern-is-required-when-us","errorCode":null,"errorMessage":"database config #%d: 'pattern' is required when using 'dir'","messagePattern":"database config #(.+?): 'pattern' is required when using 'dir'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/main.go","lineNumber":515,"sourceCode":"\t\t}\n\t\tif db.Path == \"\" && db.Dir == \"\" {\n\t\t\treturn fmt.Errorf(\"database config #%d: must specify either 'path' or 'dir'\", idx+1)\n\t\t}\n\n\t\t// Reject the same database path listed twice. The metadata directory is\n\t\t// derived from the path, so two entries would share it and race on the\n\t\t// same LTX temp files.\n\t\tif db.Path != \"\" {\n\t\t\tkey := filepath.Clean(db.Path)\n\t\t\tif first, ok := seenPaths[key]; ok {\n\t\t\t\treturn fmt.Errorf(\"database config #%d: duplicate path %q (already used by database config #%d); each database can be listed only once\", idx+1, db.Path, first)\n\t\t\t}\n\t\t\tseenPaths[key] = idx + 1\n\t\t}\n\n\t\t// When using dir, pattern must be specified\n\t\tif db.Dir != \"\" && db.Pattern == \"\" {\n\t\t\treturn fmt.Errorf(\"database config #%d: 'pattern' is required when using 'dir'\", idx+1)\n\t\t}\n\t\tif db.Watch && db.Dir == \"\" {\n\t\t\treturn fmt.Errorf(\"database config #%d: 'watch' can only be enabled with a directory\", idx+1)\n\t\t}\n\t\tif db.MetaDir != nil && db.Dir == \"\" {\n\t\t\treturn fmt.Errorf(\"database config #%d: 'meta-dir' can only be used with a directory\", idx+1)\n\t\t}\n\t\tif db.MetaPath != nil && db.MetaDir != nil {\n\t\t\treturn fmt.Errorf(\"database config #%d: cannot specify both 'meta-path' and 'meta-dir'\", idx+1)\n\t\t}\n\n\t\t// Use path or dir for identifying the config in error messages\n\t\tdbIdentifier := db.Path\n\t\tif dbIdentifier == \"\" {\n\t\t\tdbIdentifier = db.Dir\n\t\t}\n\n\t\tif db.Snapshot.Interval != nil && *db.Snapshot.Interval <= 0 {","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/main.go#L497-L533","documentation":"Config validation requires that when a database entry specifies a `dir` (directory of databases to watch), it must also specify a `pattern` that selects which files in that directory are databases. A dir without a pattern gives litestream no way to identify candidate database files, so Validate rejects the entry.","triggerScenarios":"A `dbs:` entry with `dir: /var/lib/dbs` but no `pattern:` key; configs converted from path-based entries where someone swapped `path:` for `dir:` without adding the pattern.","commonSituations":"Users adopting directory watching for many SQLite files forgetting the glob pattern; copy-pasting dir-based examples from docs that show pattern in a later snippet; hand-written configs where the pattern key is misspelled (e.g. `patterns:`), leaving `pattern` effectively empty.","solutions":["Add a `pattern` to the database entry, e.g. `pattern: \"*.db\"`, alongside `dir:`.","Verify the key is spelled exactly `pattern` (not `patterns` or `glob`) and is non-empty.","If you actually meant a single database, use `path:` instead of `dir:`.","Re-run the command with the corrected config to confirm validation passes."],"exampleFix":"# before (litestream.yml)\ndbs:\n  - dir: /var/lib/dbs\n# after\ndbs:\n  - dir: /var/lib/dbs\n    pattern: \"*.db\"","handlingStrategy":"validation","validationCode":"# fail fast before deploy\nif yq -e '.dbs[] | select(has(\"dir\") and (has(\"pattern\") | not))' litestream.yml >/dev/null; then\n  echo 'db entry with dir is missing pattern'; exit 1\nfi","typeGuard":null,"tryCatchPattern":"if err := cmd.Run(); err != nil {\n    if strings.Contains(err.Error(), \"'pattern' is required when using 'dir'\") {\n        log.Fatal(\"add pattern: \\\"*.db\\\" next to dir: in litestream.yml\")\n    }\n    log.Fatal(err)\n}","preventionTips":["Always pair `dir:` with a `pattern:` (e.g. \"*.db\") in database entries.","Check key spelling — `patterns:` or `glob:` silently leaves pattern empty.","Use `path:` instead of `dir:` when you only monitor a single database.","Validate the config file in CI or with a schema check before rollout."],"tags":["config","validation","missing-field"],"backgroundTag":"missing-required-config-field","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"}