Bumping vendor/nim-confutils and vendor/nim-serialization (#2056)

This commit is contained in:
Ivan Folgueira Bande 2023-09-21 13:12:14 +02:00 committed by GitHub
parent 5f9896448d
commit 1c4533a27a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 40 additions and 38 deletions

View File

@ -273,7 +273,7 @@ proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T =
# XXX: Here at the moment
result = crypto.PrivateKey(scheme: Secp256k1, skkey: key)
except CatchableError as e:
raise newException(ConfigurationError, "Invalid private key")
raise newException(ValueError, "Invalid private key")
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
return @[]
@ -282,7 +282,7 @@ proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
try:
result = ValidIpAddress.init(p)
except CatchableError as e:
raise newException(ConfigurationError, "Invalid IP address")
raise newException(ValueError, "Invalid IP address")
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
return @[]
@ -291,7 +291,7 @@ proc parseCmdArg*(T: type Port, p: string): T =
try:
result = Port(parseInt(p))
except CatchableError as e:
raise newException(ConfigurationError, "Invalid Port number")
raise newException(ValueError, "Invalid Port number")
proc completeCmdArg*(T: type Port, val: string): seq[string] =
return @[]
@ -300,7 +300,7 @@ proc parseCmdArg*(T: type Option[uint], p: string): T =
try:
some(parseUint(p))
except CatchableError:
raise newException(ConfigurationError, "Invalid unsigned integer")
raise newException(ValueError, "Invalid unsigned integer")
func defaultListenAddress*(conf: Chat2Conf): ValidIpAddress =
# TODO: How should we select between IPv4 and IPv6

View File

@ -134,7 +134,7 @@ proc parseCmdArg*(T: type keys.KeyPair, p: string): T =
let privkey = keys.PrivateKey.fromHex(string(p)).tryGet()
result = privkey.toKeyPair()
except CatchableError:
raise newException(ConfigurationError, "Invalid private key")
raise newException(ValueError, "Invalid private key")
proc completeCmdArg*(T: type keys.KeyPair, val: string): seq[string] =
return @[]
@ -144,7 +144,7 @@ proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T =
if key.isOk():
crypto.PrivateKey(scheme: Secp256k1, skkey: key.get())
else:
raise newException(ConfigurationError, "Invalid private key")
raise newException(ValueError, "Invalid private key")
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
return @[]
@ -153,7 +153,7 @@ proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
try:
result = ValidIpAddress.init(p)
except CatchableError:
raise newException(ConfigurationError, "Invalid IP address")
raise newException(ValueError, "Invalid IP address")
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
return @[]

View File

@ -69,7 +69,7 @@ proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
try:
result = ValidIpAddress.init(p)
except CatchableError as e:
raise newException(ConfigurationError, "Invalid IP address")
raise newException(ValueError, "Invalid IP address")
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
return @[]
@ -78,7 +78,7 @@ proc parseCmdArg*(T: type chronos.Duration, p: string): T =
try:
result = chronos.seconds(parseInt(p))
except CatchableError as e:
raise newException(ConfigurationError, "Invalid duration value")
raise newException(ValueError, "Invalid duration value")
proc completeCmdArg*(T: type chronos.Duration, val: string): seq[string] =
return @[]

View File

@ -72,7 +72,7 @@ proc parseCmdArg*(T: type chronos.Duration, p: string): T =
try:
result = chronos.seconds(parseInt(p))
except CatchableError:
raise newException(ConfigurationError, "Invalid timeout value")
raise newException(ValueError, "Invalid timeout value")
proc completeCmdArg*(T: type chronos.Duration, val: string): seq[string] =
return @[]

View File

@ -25,7 +25,6 @@ export
confEnvvarDefs,
confEnvvarNet
type ConfResult*[T] = Result[T, string]
type ProtectedTopic* = object
topic*: string
@ -456,7 +455,7 @@ proc parseCmdArg*(T: type crypto.PrivateKey, p: string): T =
let key = SkPrivateKey.init(utils.fromHex(p)).tryGet()
crypto.PrivateKey(scheme: Secp256k1, skkey: key)
except CatchableError:
raise newException(ConfigurationError, "Invalid private key")
raise newException(ValueError, "Invalid private key")
proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
return @[]
@ -464,11 +463,11 @@ proc completeCmdArg*(T: type crypto.PrivateKey, val: string): seq[string] =
proc parseCmdArg*(T: type ProtectedTopic, p: string): T =
let elements = p.split(":")
if elements.len != 2:
raise newException(ConfigurationError, "Invalid format for protected topic expected topic:publickey")
raise newException(ValueError, "Invalid format for protected topic expected topic:publickey")
let publicKey = secp256k1.SkPublicKey.fromHex(elements[1])
if publicKey.isErr:
raise newException(ConfigurationError, "Invalid public key")
raise newException(ValueError, "Invalid public key")
return ProtectedTopic(topic: elements[0], key: publicKey.get())
@ -479,7 +478,7 @@ proc parseCmdArg*(T: type ValidIpAddress, p: string): T =
try:
ValidIpAddress.init(p)
except CatchableError:
raise newException(ConfigurationError, "Invalid IP address")
raise newException(ValueError, "Invalid IP address")
proc completeCmdArg*(T: type ValidIpAddress, val: string): seq[string] =
return @[]
@ -489,12 +488,11 @@ proc defaultListenAddress*(): ValidIpAddress =
# Maybe there should be a config option for this.
(static ValidIpAddress.init("0.0.0.0"))
proc parseCmdArg*(T: type Port, p: string): T =
try:
Port(parseInt(p))
except CatchableError:
raise newException(ConfigurationError, "Invalid Port number")
raise newException(ValueError, "Invalid Port number")
proc completeCmdArg*(T: type Port, val: string): seq[string] =
return @[]
@ -503,13 +501,13 @@ proc parseCmdArg*(T: type Option[int], p: string): T =
try:
some(parseInt(p))
except CatchableError:
raise newException(ConfigurationError, "Invalid number")
raise newException(ValueError, "Invalid number")
proc parseCmdArg*(T: type Option[uint], p: string): T =
try:
some(parseUint(p))
except CatchableError:
raise newException(ConfigurationError, "Invalid unsigned integer")
raise newException(ValueError, "Invalid unsigned integer")
## Configuration validation
@ -531,7 +529,6 @@ proc readValue*(r: var TomlReader, value: var crypto.PrivateKey) {.raises: [Seri
except CatchableError:
raise newException(SerializationError, getCurrentExceptionMsg())
proc readValue*(r: var EnvvarReader, value: var crypto.PrivateKey) {.raises: [SerializationError].} =
try:
value = parseCmdArg(crypto.PrivateKey, r.readValue(string))
@ -556,7 +553,8 @@ proc load*(T: type WakuNodeConf, version=""): ConfResult[T] =
try:
let conf = WakuNodeConf.load(
version=version,
secondarySources = proc (conf: WakuNodeConf, sources: auto) =
secondarySources = proc (conf: WakuNodeConf, sources: auto)
{.gcsafe, raises: [ConfigurationError].} =
sources.addConfigFile(Envvar, InputFile("wakunode2"))
if conf.configFile.isSome():

View File

@ -12,7 +12,6 @@ import
../../waku/common/confutils/envvar/defs as confEnvvarDefs,
../../waku/common/confutils/envvar/std/net as confEnvvarNet
type ConfResult[T] = Result[T, string]
type TestConf = object
@ -34,13 +33,13 @@ type TestConf = object
defaultValue: 60000,
name: "tcp-port" }: Port
{.push warning[ProveInit]: off.}
proc load*(T: type TestConf, prefix: string): ConfResult[T] =
try:
let conf = TestConf.load(
secondarySources = proc (conf: TestConf, sources: auto) =
secondarySources = proc (conf: TestConf, sources: auto)
{.gcsafe, raises: [ConfigurationError].} =
sources.addConfigFile(Envvar, InputFile(prefix))
)
ok(conf)
@ -49,7 +48,6 @@ proc load*(T: type TestConf, prefix: string): ConfResult[T] =
{.pop.}
suite "nim-confutils - envvar":
test "load configuration from environment variables":
## Given

@ -1 +1 @@
Subproject commit c8063eb8142aeb6489ded24f3da908bc7f921b7b
Subproject commit 674c9e4c8e0cad2b7193cc9a59c12d39a397750f

@ -1 +1 @@
Subproject commit 5b7cea55efeb074daa8abd8146a03a34adb4521a
Subproject commit 4bdbc29e54fe54049950e352bb969aab97173b35

View File

@ -3,7 +3,6 @@ when (NimMajor, NimMinor) < (1, 4):
else:
{.push raises: [].}
import
std/strutils,
stew/shims/net
@ -14,15 +13,14 @@ export
net,
envvar_serialization
proc readValue*(r: var EnvvarReader, value: var ValidIpAddress) {.raises: [SerializationError].} =
try:
value = ValidIpAddress.init(r.readValue(string))
except ValueError:
raise newException(EnvvarError, "Invalid IP address")
except ValueError, IOError:
raise newException(SerializationError, "Invalid IP address: " & getCurrentExceptionMsg())
proc readValue*(r: var EnvvarReader, value: var Port) {.raises: [SerializationError, ValueError].} =
proc readValue*(r: var EnvvarReader, value: var Port) {.raises: [SerializationError].} =
try:
value = parseUInt(r.readValue(string)).Port
except ValueError:
raise newException(EnvvarError, "Invalid Port")
except ValueError, IOError:
raise newException(SerializationError, "Invalid Port: " & getCurrentExceptionMsg())

View File

@ -39,7 +39,7 @@ proc handleReadException*(r: EnvvarReader,
proc init*(T: type EnvvarReader, prefix: string): T =
result.prefix = prefix
proc readValue*[T](r: var EnvvarReader, value: var T) {.raises: [ValueError, SerializationError].} =
proc readValue*[T](r: var EnvvarReader, value: var T) {.raises: [SerializationError].} =
mixin readValue
when T is string:
@ -48,7 +48,11 @@ proc readValue*[T](r: var EnvvarReader, value: var T) {.raises: [ValueError, Ser
elif T is (SomePrimitives or range):
let key = constructKey(r.prefix, r.key)
getValue(key, value)
try:
getValue(key, value)
except ValueError:
raise newException(SerializationError,
"Couldn't getValue SomePrimitives: " & getCurrentExceptionMsg())
elif T is Option:
template getUnderlyingType[T](_: Option[T]): untyped = T
@ -58,7 +62,11 @@ proc readValue*[T](r: var EnvvarReader, value: var T) {.raises: [ValueError, Ser
when uType is string:
value = some(os.getEnv(key))
else:
value = some(r.readValue(uType))
try:
value = some(r.readValue(uType))
except ValueError, IOError:
raise newException(SerializationError,
"Couldn't read Option value: " & getCurrentExceptionMsg())
elif T is (seq or array):
when uTypeIsPrimitives(T):