fix: abort startup on explicitly empty db_url instead of deriving
The derived file:...state.sqlite3 URL is a default and defaults apply only to omitted keys: db_url set to an empty string now aborts naming the key, matching the existing behavior of state_dir: "".
This commit is contained in:
@@ -113,9 +113,19 @@ func newFromSmartConfig(sc *smartconfig.Config) (*Config, error) {
|
|||||||
"upstream_connections_per_host", DefaultUpstreamConnectionsPerHost),
|
"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", "")
|
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)
|
c.DBURL = fmt.Sprintf("file:%s/state.sqlite3?_journal_mode=WAL", c.StateDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user