aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorViktor TrĂ³n <viktor.tron@gmail.com>2018-10-02 15:31:44 +0800
committerGitHub <noreply@github.com>2018-10-02 15:31:44 +0800
commit0bf3065fb49f04fe237c315e65a6434d840b6171 (patch)
tree83d3b9e3b597b213b61e9ccc92fbadeeacaa7126 /cmd
parent83116a3479beb2506c3be59a21f7616ae59d4dbe (diff)
parentbf37241eb5031aa081152f654f28a65496bc7586 (diff)
downloaddexon-0bf3065fb49f04fe237c315e65a6434d840b6171.tar
dexon-0bf3065fb49f04fe237c315e65a6434d840b6171.tar.gz
dexon-0bf3065fb49f04fe237c315e65a6434d840b6171.tar.bz2
dexon-0bf3065fb49f04fe237c315e65a6434d840b6171.tar.lz
dexon-0bf3065fb49f04fe237c315e65a6434d840b6171.tar.xz
dexon-0bf3065fb49f04fe237c315e65a6434d840b6171.tar.zst
dexon-0bf3065fb49f04fe237c315e65a6434d840b6171.zip
Merge pull request #17771 from ethersphere/cmd-config-errors
swarm: handle errors in cmdLineOverride and envVarsOverride
Diffstat (limited to 'cmd')
-rw-r--r--cmd/swarm/config.go43
1 files changed, 30 insertions, 13 deletions
diff --git a/cmd/swarm/config.go b/cmd/swarm/config.go
index 9d6fe41a7..16001010d 100644
--- a/cmd/swarm/config.go
+++ b/cmd/swarm/config.go
@@ -176,8 +176,12 @@ func cmdLineOverride(currentConfig *bzzapi.Config, ctx *cli.Context) *bzzapi.Con
}
if networkid := ctx.GlobalString(SwarmNetworkIdFlag.Name); networkid != "" {
- if id, _ := strconv.Atoi(networkid); id != 0 {
- currentConfig.NetworkID = uint64(id)
+ id, err := strconv.ParseUint(networkid, 10, 64)
+ if err != nil {
+ utils.Fatalf("invalid cli flag %s: %v", SwarmNetworkIdFlag.Name, err)
+ }
+ if id != 0 {
+ currentConfig.NetworkID = id
}
}
@@ -270,8 +274,12 @@ func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) {
}
if networkid := os.Getenv(SWARM_ENV_NETWORK_ID); networkid != "" {
- if id, _ := strconv.Atoi(networkid); id != 0 {
- currentConfig.NetworkID = uint64(id)
+ id, err := strconv.ParseUint(networkid, 10, 64)
+ if err != nil {
+ utils.Fatalf("invalid environment variable %s: %v", SWARM_ENV_NETWORK_ID, err)
+ }
+ if id != 0 {
+ currentConfig.NetworkID = id
}
}
@@ -289,27 +297,34 @@ func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) {
}
if swapenable := os.Getenv(SWARM_ENV_SWAP_ENABLE); swapenable != "" {
- if swap, err := strconv.ParseBool(swapenable); err != nil {
- currentConfig.SwapEnabled = swap
+ swap, err := strconv.ParseBool(swapenable)
+ if err != nil {
+ utils.Fatalf("invalid environment variable %s: %v", SWARM_ENV_SWAP_ENABLE, err)
}
+ currentConfig.SwapEnabled = swap
}
if syncdisable := os.Getenv(SWARM_ENV_SYNC_DISABLE); syncdisable != "" {
- if sync, err := strconv.ParseBool(syncdisable); err != nil {
- currentConfig.SyncEnabled = !sync
+ sync, err := strconv.ParseBool(syncdisable)
+ if err != nil {
+ utils.Fatalf("invalid environment variable %s: %v", SWARM_ENV_SYNC_DISABLE, err)
}
+ currentConfig.SyncEnabled = !sync
}
if v := os.Getenv(SWARM_ENV_DELIVERY_SKIP_CHECK); v != "" {
- if skipCheck, err := strconv.ParseBool(v); err != nil {
+ skipCheck, err := strconv.ParseBool(v)
+ if err != nil {
currentConfig.DeliverySkipCheck = skipCheck
}
}
if v := os.Getenv(SWARM_ENV_SYNC_UPDATE_DELAY); v != "" {
- if d, err := time.ParseDuration(v); err != nil {
- currentConfig.SyncUpdateDelay = d
+ d, err := time.ParseDuration(v)
+ if err != nil {
+ utils.Fatalf("invalid environment variable %s: %v", SWARM_ENV_SYNC_UPDATE_DELAY, err)
}
+ currentConfig.SyncUpdateDelay = d
}
if max := os.Getenv(SWARM_ENV_MAX_STREAM_PEER_SERVERS); max != "" {
@@ -321,9 +336,11 @@ func envVarsOverride(currentConfig *bzzapi.Config) (config *bzzapi.Config) {
}
if lne := os.Getenv(SWARM_ENV_LIGHT_NODE_ENABLE); lne != "" {
- if lightnode, err := strconv.ParseBool(lne); err != nil {
- currentConfig.LightNodeEnabled = lightnode
+ lightnode, err := strconv.ParseBool(lne)
+ if err != nil {
+ utils.Fatalf("invalid environment variable %s: %v", SWARM_ENV_LIGHT_NODE_ENABLE, err)
}
+ currentConfig.LightNodeEnabled = lightnode
}
if swapapi := os.Getenv(SWARM_ENV_SWAP_API); swapapi != "" {