Skip to content

Commit aa3bdb1

Browse files
committed
Helpful error message when the user fails to use an array type in TOML
This applies to fields such as `web3-url` which are mapped to array in TOML in a way that may surprise the user.
1 parent 7340e7c commit aa3bdb1

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

beacon_chain/nimbus_binary_common.nim

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,30 @@ template makeBannerAndConfig*(clientId: string, ConfType: type): untyped =
184184

185185
# TODO for some reason, copyrights are printed when doing `--help`
186186
{.push warning[ProveInit]: off.}
187-
let config = ConfType.load(
188-
version = version, # but a short version string makes more sense...
189-
copyrightBanner = clientId,
190-
secondarySources = proc (config: ConfType, sources: auto) =
191-
if config.configFile.isSome:
192-
sources.addConfigFile(Toml, config.configFile.get)
193-
)
187+
let config = try:
188+
ConfType.load(
189+
version = version, # but a short version string makes more sense...
190+
copyrightBanner = clientId,
191+
secondarySources = proc (config: ConfType, sources: auto) =
192+
if config.configFile.isSome:
193+
sources.addConfigFile(Toml, config.configFile.get)
194+
)
195+
except CatchableError as err:
196+
# We need to log to stderr here, because logging hasn't been configured yet
197+
stderr.write "Failure while loading the configuration:\n"
198+
stderr.write err.msg
199+
stderr.write "\n"
200+
201+
if err[] of ConfigurationError and
202+
err.parent != nil and
203+
err.parent[] of TomlFieldReadingError:
204+
let fieldName = ((ref TomlFieldReadingError)(err.parent)).field
205+
if fieldName in ["web3-url", "bootstrap-node",
206+
"direct-peer", "validator-monitor-pubkey"]:
207+
stderr.write "Since the '" & fieldName & "' option is allowed to " &
208+
"have more than one value, please make sure to supply " &
209+
"a properly formatted TOML array\n"
210+
quit 1
194211
{.pop.}
195212
config
196213

vendor/nim-serialization

0 commit comments

Comments
 (0)