From aa3bdb122804035a33e0a5ae78765060be3aed2c Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Wed, 9 Mar 2022 18:28:17 +0200 Subject: [PATCH] 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. --- beacon_chain/nimbus_binary_common.nim | 31 +++++++++++++++++++++------ vendor/nim-confutils | 2 +- vendor/nim-json-serialization | 2 +- vendor/nim-serialization | 2 +- vendor/nim-toml-serialization | 2 +- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/beacon_chain/nimbus_binary_common.nim b/beacon_chain/nimbus_binary_common.nim index be67b3917..bdf57fa8a 100644 --- a/beacon_chain/nimbus_binary_common.nim +++ b/beacon_chain/nimbus_binary_common.nim @@ -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 diff --git a/vendor/nim-confutils b/vendor/nim-confutils index 0a88d30e0..585059d2f 160000 --- a/vendor/nim-confutils +++ b/vendor/nim-confutils @@ -1 +1 @@ -Subproject commit 0a88d30e0035ad761b41886251149d54e65a916a +Subproject commit 585059d2fba17a2212fe644782a675b4a6b8dca1 diff --git a/vendor/nim-json-serialization b/vendor/nim-json-serialization index a12beabd2..461fd03ed 160000 --- a/vendor/nim-json-serialization +++ b/vendor/nim-json-serialization @@ -1 +1 @@ -Subproject commit a12beabd2fa721407bc99492a0075ce43ad9994d +Subproject commit 461fd03edb300b7946544b34442d1a05d4ef2270 diff --git a/vendor/nim-serialization b/vendor/nim-serialization index 37bc0db55..9631fbd1c 160000 --- a/vendor/nim-serialization +++ b/vendor/nim-serialization @@ -1 +1 @@ -Subproject commit 37bc0db558d85711967acb16e9bb822b06911d46 +Subproject commit 9631fbd1c81c8b25ff8740df440ca7ba87fa6131 diff --git a/vendor/nim-toml-serialization b/vendor/nim-toml-serialization index f4fb6c6ef..90369dd67 160000 --- a/vendor/nim-toml-serialization +++ b/vendor/nim-toml-serialization @@ -1 +1 @@ -Subproject commit f4fb6c6ef833bff6649f26830c6a8401c945aa38 +Subproject commit 90369dd67b4a41109e26716829f6f3f077eddf38