diff --git a/internal/config/config.go b/internal/config/config.go index 269ec8e..95864fa 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -113,9 +113,19 @@ func newFromSmartConfig(sc *smartconfig.Config) (*Config, error) { "upstream_connections_per_host", DefaultUpstreamConnectionsPerHost), } - // Build DBURL from StateDir if not explicitly set + // Build DBURL from StateDir if not explicitly set. The derived URL + // is a default: it applies only when db_url is omitted, never to an + // explicitly empty value. c.DBURL = loader.stringVal("db_url", "") - if c.DBURL == "" { + if c.DBURL == "" && loader.err == nil { + if sc != nil { + if _, present := sc.Get("db_url"); present { + return nil, fmt.Errorf( + "config key %q: value must not be empty; omit the key to derive it from state_dir", + "db_url") + } + } + c.DBURL = fmt.Sprintf("file:%s/state.sqlite3?_journal_mode=WAL", c.StateDir) }