fix: use `fleetFromString` function to prevent panic for unknown values (#13699)
This commit is contained in:
parent
1dc03624d6
commit
28d8145136
|
@ -1,5 +1,7 @@
|
|||
import sys, os, re
|
||||
import sqlcipher3
|
||||
import readline
|
||||
|
||||
from getpass import getpass
|
||||
from common import PasswordFunctions
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import json, typetraits, tables, sequtils
|
||||
import json, typetraits, tables, sequtils, strutils
|
||||
|
||||
type
|
||||
Fleet* {.pure.} = enum
|
||||
|
@ -76,3 +76,9 @@ proc getMailservers*(self: FleetConfiguration, fleet: Fleet): Table[string, stri
|
|||
result = initTable[string,string]()
|
||||
return
|
||||
result = self.fleet[$fleet][fleetKey]
|
||||
|
||||
proc fleetFromString*(fleet: string): Fleet {.inline.} =
|
||||
try:
|
||||
return parseEnum[Fleet](fleet)
|
||||
except:
|
||||
return Fleet.Undefined
|
||||
|
|
|
@ -35,7 +35,7 @@ proc init*(self: Controller) =
|
|||
discard
|
||||
|
||||
proc getFleet*(self: Controller): string =
|
||||
self.nodeConfigurationService.getFleetAsString()
|
||||
return self.nodeConfigurationService.getFleetAsString()
|
||||
|
||||
proc changeFleetTo*(self: Controller, fleet: string) =
|
||||
if (not self.nodeConfigurationService.setFleet(fleet)):
|
||||
|
|
|
@ -129,7 +129,7 @@ proc getFleet*(self: Service): Fleet =
|
|||
result = self.settingsService.getFleet()
|
||||
if result == Fleet.Undefined:
|
||||
let fleetFromNodeConfig = self.configuration.ClusterConfig.Fleet
|
||||
result = parseEnum[Fleet](fleetFromNodeConfig)
|
||||
result = fleetFromString(fleetFromNodeConfig)
|
||||
|
||||
proc getFleetAsString*(self: Service): string =
|
||||
result = $self.getFleet()
|
||||
|
@ -148,7 +148,7 @@ proc setFleet*(self: Service, fleet: string): bool =
|
|||
error "error saving fleet ", procName="setFleet"
|
||||
return false
|
||||
|
||||
let fleetType = parseEnum[Fleet](fleet)
|
||||
let fleetType = fleetFromString(fleet)
|
||||
var newConfiguration = self.configuration
|
||||
newConfiguration.ClusterConfig.Fleet = fleet
|
||||
newConfiguration.ClusterConfig.BootNodes = self.fleetConfiguration.getNodes(fleetType, FleetNodes.Bootnodes)
|
||||
|
|
|
@ -18,7 +18,7 @@ export stickers_dto
|
|||
# Default values:
|
||||
const DEFAULT_CURRENCY* = "USD"
|
||||
const DEFAULT_TELEMETRY_SERVER_URL* = "https://telemetry.status.im"
|
||||
const DEFAULT_FLEET* = $Fleet.ShardsTest
|
||||
const DEFAULT_FLEET* = Fleet.ShardsTest
|
||||
|
||||
# Signals:
|
||||
const SIGNAL_CURRENCY_UPDATED* = "currencyUpdated"
|
||||
|
@ -398,7 +398,7 @@ QtObject:
|
|||
|
||||
proc getFleet*(self: Service): Fleet =
|
||||
let fleetAsString = self.getFleetAsString()
|
||||
return parseEnum[Fleet](fleetAsString)
|
||||
return fleetFromString(fleetAsString)
|
||||
|
||||
proc getCurrentUserStatus*(self: Service): CurrentUserStatus =
|
||||
self.settings.currentUserStatus
|
||||
|
@ -413,6 +413,8 @@ QtObject:
|
|||
return ""
|
||||
|
||||
proc pinMailserver*(self: Service, mailserverID: string, fleet: Fleet): bool =
|
||||
if fleet == Fleet.Undefined:
|
||||
return false
|
||||
var newMailserverJsonObj = self.settings.pinnedMailserver.pinnedMailserverToJsonNode()
|
||||
newMailserverJsonObj[$fleet] = %* mailserverID
|
||||
if(self.saveSetting(KEY_PINNED_MAILSERVERS, newMailserverJsonObj)):
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit ba7faea027b1e87e6d53b0e487df2469cd6271f2
|
||||
Subproject commit 23ee898754f71341dc53e71657ef0633165f7bd3
|
Loading…
Reference in New Issue