Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/node: refuse to start if viper shadows keys
If a node is started with VOCDONI_VOCHAIN=foo, then all flags or config keys under the vochain group are broken. They don't bind properly to the config type, and their defaults don't get applied properly. This then leads to confusing failures, since values are left empty: $ VOCDONI_VOCHAIN=dev go run ./cmd/node [...] 2023-12-25T00:05:54.798+01:00 FTL node/main.go:449 > invalid P2PListen "": missing port in address goroutine 1 [running]: runtime/debug.Stack() /home/mvdan/tip/src/runtime/debug/stack.go:24 +0x5e go.vocdoni.io/dvote/log.Fatal({0xc0006bbf20, 0x1, 0x1}) /home/mvdan/src/voc/log/log.go:212 +0x65 main.main() /home/mvdan/src/voc/cmd/node/main.go:449 +0xc26 Don't let the node start if we know this would happen via an env var. It's technically still possible for this to happen via the YAML config, but it feels far less likely to be the case. We can avoid repetition in the code by looping over the groups of config key prefixes we use. It turns out that viper is always case insensitive, so we don't have to worry about "tls" vs "TLS". While here, add context to these SplitHostPort errors, since the lone "missing port in address" error seemed confusing.
- Loading branch information