benbjohnson/litestream · error
cannot create database from config: %w
Error message
cannot create database from config: %w
What it means
This error wraps any failure that occurs while constructing a litestream.DB from a serialized database config (TOML/JSON config snippet) during `litestream reset`. NewDBFromConfig parses the config and initializes the DB object; if the config is malformed, references a missing/invalid replica section, or fails internal validation, the underlying error is wrapped and returned. The reset command aborts before touching any local LTX state, so no data is deleted when this fires.
Source
Thrown at cmd/litestream/reset.go:79
dbConfig = dbc
break
}
}
}
// If no config found, check if database file exists
if _, err := os.Stat(dbPath); os.IsNotExist(err) {
return fmt.Errorf("database does not exist: %s", dbPath)
} else if err != nil {
return fmt.Errorf("cannot access database: %w", err)
}
// Create DB instance
var db *litestream.DB
if dbConfig != nil {
db, err = NewDBFromConfig(dbConfig)
if err != nil {
return fmt.Errorf("cannot create database from config: %w", err)
}
} else {
db = litestream.NewDB(dbPath)
}
// Check if meta path exists
metaPath := db.MetaPath()
if _, err := os.Stat(metaPath); os.IsNotExist(err) {
fmt.Printf("No local state to reset for %s\n", dbPath)
fmt.Printf("Meta directory does not exist: %s\n", metaPath)
return nil
}
if *dryRun {
files, err := localLTXFiles(db.LTXDir())
if err != nil {
return fmt.Errorf("dry run failed: %w", err)
}View on GitHub (pinned to 4ed7a308f6)
Solutions
- Validate the config file with `litestream -config <file> ...` or by running another command (e.g. `litestream ltx`) that loads the same config, and fix the reported parse/validation error
- Check the wrapped inner error (%w) in the message — it names the exact field or section that failed
- Compare the db section against current litestream config docs for field renames after upgrading
- If you only have a plain db path, omit -config/-db-config so reset falls back to litestream.NewDB(dbPath)
Example fix
// before (invalid config field)
dbs:
- path: /var/lib/db/app.db
replicas:
- url: s3://BUCKET/prefix
sync-interval: sometimes
// after
dbs:
- path: /var/lib/db/app.db
replicas:
- url: s3://BUCKET/prefix
sync-interval: 1s Defensive patterns
Strategy: validation
Validate before calling
// Validate config before invoking reset
cfg, err := os.ReadFile(configPath)
if err != nil { return err }
if !bytes.Contains(cfg, []byte("[[dbs]]")) && !bytes.Contains(cfg, []byte("dbs:")) {
return fmt.Errorf("config %s has no db sections", configPath)
}
// smoke-test the same config through another command first:
// litestream ltx -config <file> ... Prevention
- Keep db configs generated from one template/version; re-validate after upgrades
- Run a non-destructive command with the same -config before running reset
- Omit -config when you only have a plain db path
When it happens
Trigger: Running `litestream reset -config litestream.yml` (or reset with a db path whose config stanza is resolved from the config file) where the db config block is invalid: unknown fields, bad DSN/path, invalid replica URLs, or a config that NewDBFromConfig cannot deserialize or validate.
Common situations: Typo'd or hand-edited config files; using a config generated for an older litestream version with renamed fields; pointing -config at a file with no matching db block; passing a replica URL where a db config was expected.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- config file not found
- database not found in config: %s
- heartbeat URL must be a valid HTTP or HTTPS URL
- heartbeat interval must be at least 1 minute
- invalid -timestamp, must specify in ISO 8601 format (e.g. 20
AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06).
Data as JSON: /api/errors/3d1a7448533d5674.
Report an issue: GitHub.