mirror of https://github.com/status-im/nim-eth.git
use correct exception in `parseCmdArg` (#614)
`parseCmdArg` is expected to raise `ValueError` but for `enr.Record`, `Node`, `PrivateKey`, and `NatConfig`, we raise `ConfigurationError`. Change to `ValueError` instead.
This commit is contained in:
parent
c608426d03
commit
99d980c3f6
|
@ -1,3 +1,11 @@
|
||||||
|
# Copyright (c) 2020-2023 Status Research & Development GmbH
|
||||||
|
# Licensed under either of
|
||||||
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||||
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||||
|
# at your option.
|
||||||
|
# This file may not be copied, modified, or distributed except according to
|
||||||
|
# those terms.
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[options, strutils, tables, sets],
|
std/[options, strutils, tables, sets],
|
||||||
confutils, confutils/std/net, chronicles, chronicles/topics_registry,
|
confutils, confutils/std/net, chronicles, chronicles/topics_registry,
|
||||||
|
@ -104,35 +112,35 @@ func defaultListenAddress*(conf: DiscoveryConf): ValidIpAddress =
|
||||||
func defaultAdminListenAddress*(conf: DiscoveryConf): ValidIpAddress =
|
func defaultAdminListenAddress*(conf: DiscoveryConf): ValidIpAddress =
|
||||||
(static ValidIpAddress.init("127.0.0.1"))
|
(static ValidIpAddress.init("127.0.0.1"))
|
||||||
|
|
||||||
proc parseCmdArg*(T: type enr.Record, p: string): T =
|
proc parseCmdArg*(T: type enr.Record, p: string): T {.raises: [ValueError].} =
|
||||||
if not fromURI(result, p):
|
if not fromURI(result, p):
|
||||||
raise newException(ConfigurationError, "Invalid ENR")
|
raise newException(ValueError, "Invalid ENR")
|
||||||
|
|
||||||
proc completeCmdArg*(T: type enr.Record, val: string): seq[string] =
|
proc completeCmdArg*(T: type enr.Record, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
|
|
||||||
proc parseCmdArg*(T: type Node, p: string): T =
|
proc parseCmdArg*(T: type Node, p: string): T {.raises: [ValueError].} =
|
||||||
var record: enr.Record
|
var record: enr.Record
|
||||||
if not fromURI(record, p):
|
if not fromURI(record, p):
|
||||||
raise newException(ConfigurationError, "Invalid ENR")
|
raise newException(ValueError, "Invalid ENR")
|
||||||
|
|
||||||
let n = newNode(record)
|
let n = newNode(record)
|
||||||
if n.isErr:
|
if n.isErr:
|
||||||
raise newException(ConfigurationError, $n.error)
|
raise newException(ValueError, $n.error)
|
||||||
|
|
||||||
if n[].address.isNone():
|
if n[].address.isNone():
|
||||||
raise newException(ConfigurationError, "ENR without address")
|
raise newException(ValueError, "ENR without address")
|
||||||
|
|
||||||
n[]
|
n[]
|
||||||
|
|
||||||
proc completeCmdArg*(T: type Node, val: string): seq[string] =
|
proc completeCmdArg*(T: type Node, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
|
|
||||||
proc parseCmdArg*(T: type PrivateKey, p: string): T =
|
proc parseCmdArg*(T: type PrivateKey, p: string): T {.raises: [ValueError].} =
|
||||||
try:
|
try:
|
||||||
result = PrivateKey.fromHex(string(p)).tryGet()
|
result = PrivateKey.fromHex(string(p)).tryGet()
|
||||||
except CatchableError:
|
except CatchableError:
|
||||||
raise newException(ConfigurationError, "Invalid private key")
|
raise newException(ValueError, "Invalid private key")
|
||||||
|
|
||||||
proc completeCmdArg*(T: type PrivateKey, val: string): seq[string] =
|
proc completeCmdArg*(T: type PrivateKey, val: string): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
|
|
Loading…
Reference in New Issue