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.
This commit is contained in:
Zahary Karadjov 2022-03-09 18:28:17 +02:00
parent 7340e7cab9
commit aa3bdb1228
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
5 changed files with 28 additions and 11 deletions

View File

@ -184,13 +184,30 @@ template makeBannerAndConfig*(clientId: string, ConfType: type): untyped =
# TODO for some reason, copyrights are printed when doing `--help`
{.push warning[ProveInit]: off.}
let config = ConfType.load(
version = version, # but a short version string makes more sense...
copyrightBanner = clientId,
secondarySources = proc (config: ConfType, sources: auto) =
if config.configFile.isSome:
sources.addConfigFile(Toml, config.configFile.get)
)
let config = try:
ConfType.load(
version = version, # but a short version string makes more sense...
copyrightBanner = clientId,
secondarySources = proc (config: ConfType, sources: auto) =
if config.configFile.isSome:
sources.addConfigFile(Toml, config.configFile.get)
)
except CatchableError as err:
# We need to log to stderr here, because logging hasn't been configured yet
stderr.write "Failure while loading the configuration:\n"
stderr.write err.msg
stderr.write "\n"
if err[] of ConfigurationError and
err.parent != nil and
err.parent[] of TomlFieldReadingError:
let fieldName = ((ref TomlFieldReadingError)(err.parent)).field
if fieldName in ["web3-url", "bootstrap-node",
"direct-peer", "validator-monitor-pubkey"]:
stderr.write "Since the '" & fieldName & "' option is allowed to " &
"have more than one value, please make sure to supply " &
"a properly formatted TOML array\n"
quit 1
{.pop.}
config

@ -1 +1 @@
Subproject commit 0a88d30e0035ad761b41886251149d54e65a916a
Subproject commit 585059d2fba17a2212fe644782a675b4a6b8dca1

@ -1 +1 @@
Subproject commit a12beabd2fa721407bc99492a0075ce43ad9994d
Subproject commit 461fd03edb300b7946544b34442d1a05d4ef2270

@ -1 +1 @@
Subproject commit 37bc0db558d85711967acb16e9bb822b06911d46
Subproject commit 9631fbd1c81c8b25ff8740df440ca7ba87fa6131

@ -1 +1 @@
Subproject commit f4fb6c6ef833bff6649f26830c6a8401c945aa38
Subproject commit 90369dd67b4a41109e26716829f6f3f077eddf38