From 5297e6033a2c3716ca0aa35a62652928c89b9ced Mon Sep 17 00:00:00 2001 From: sneak Date: Fri, 7 Aug 2026 17:03:12 +0000 Subject: [PATCH] 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: "". --- internal/config/config.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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) }