diff --git a/beacon_chain/beacon_chain_db.nim b/beacon_chain/beacon_chain_db.nim index 6a9d3f547..6866f17bc 100644 --- a/beacon_chain/beacon_chain_db.nim +++ b/beacon_chain/beacon_chain_db.nim @@ -406,8 +406,10 @@ proc new*(T: type BeaconChainDB, SqStoreRef.init("", "test", readOnly = readOnly, inMemory = true).expect( "working database (out of memory?)") else: - let s = secureCreatePath(dir) - doAssert s.isOk # TODO(zah) Handle this in a better way + if (let res = secureCreatePath(dir); res.isErr): + fatal "Failed to create create database directory", + path = dir, err = ioErrorMsg(res.error) + quit 1 SqStoreRef.init( dir, "nbc", readOnly = readOnly, manualCheckpoint = true).expectDb() diff --git a/beacon_chain/conf.nim b/beacon_chain/conf.nim index 7950c8463..7ce246e32 100644 --- a/beacon_chain/conf.nim +++ b/beacon_chain/conf.nim @@ -894,15 +894,15 @@ func dumpDirOutgoing*(config: AnyConf): string = proc createDumpDirs*(config: BeaconNodeConf) = if config.dumpEnabled: - let resInv = secureCreatePath(config.dumpDirInvalid) - if resInv.isErr(): - warn "Could not create dump directory", path = config.dumpDirInvalid - let resInc = secureCreatePath(config.dumpDirIncoming) - if resInc.isErr(): - warn "Could not create dump directory", path = config.dumpDirIncoming - let resOut = secureCreatePath(config.dumpDirOutgoing) - if resOut.isErr(): - warn "Could not create dump directory", path = config.dumpDirOutgoing + if (let res = secureCreatePath(config.dumpDirInvalid); res.isErr): + warn "Could not create dump directory", + path = config.dumpDirInvalid, err = ioErrorMsg(res.error) + if (let res = secureCreatePath(config.dumpDirIncoming); res.isErr): + warn "Could not create dump directory", + path = config.dumpDirIncoming, err = ioErrorMsg(res.error) + if (let res = secureCreatePath(config.dumpDirOutgoing); res.isErr): + warn "Could not create dump directory", + path = config.dumpDirOutgoing, err = ioErrorMsg(res.error) func parseCmdArg*(T: type GraffitiBytes, input: TaintedString): T {.raises: [ValueError, Defect].} = diff --git a/beacon_chain/deposits.nim b/beacon_chain/deposits.nim index 86f3624c4..a25f48aa9 100644 --- a/beacon_chain/deposits.nim +++ b/beacon_chain/deposits.nim @@ -374,14 +374,14 @@ proc doDeposits*(config: BeaconNodeConf, rng: var BrHmacDrbgContext) {. swap(seed, walletRes.get.seed) walletPath = walletRes.get.walletPath - let vres = secureCreatePath(config.outValidatorsDir) - if vres.isErr(): - fatal "Could not create directory", path = config.outValidatorsDir + if (let res = secureCreatePath(config.outValidatorsDir); res.isErr): + fatal "Could not create directory", + path = config.outValidatorsDir, err = ioErrorMsg(res.error) quit QuitFailure - let sres = secureCreatePath(config.outSecretsDir) - if sres.isErr(): - fatal "Could not create directory", path = config.outSecretsDir + if (let res = secureCreatePath(config.outSecretsDir); res.isErr): + fatal "Could not create directory", + path = config.outSecretsDir, err = ioErrorMsg(res.error) quit QuitFailure let deposits = generateDeposits( diff --git a/beacon_chain/eth1/deposit_contract.nim b/beacon_chain/eth1/deposit_contract.nim index 908e249b5..bbd57d93b 100644 --- a/beacon_chain/eth1/deposit_contract.nim +++ b/beacon_chain/eth1/deposit_contract.nim @@ -198,15 +198,13 @@ proc main() {.async.} = seed = getSeed(mnemonic, KeyStorePass.init "") cfg = getRuntimeConfig(conf.eth2Network) - let vres = secureCreatePath(string conf.outValidatorsDir) - if vres.isErr(): + if (let res = secureCreatePath(string conf.outValidatorsDir); res.isErr): warn "Could not create validators folder", - path = string conf.outValidatorsDir, err = ioErrorMsg(vres.error) + path = string conf.outValidatorsDir, err = ioErrorMsg(res.error) - let sres = secureCreatePath(string conf.outSecretsDir) - if sres.isErr(): + if (let res = secureCreatePath(string conf.outSecretsDir); res.isErr): warn "Could not create secrets folder", - path = string conf.outSecretsDir, err = ioErrorMsg(sres.error) + path = string conf.outSecretsDir, err = ioErrorMsg(res.error) let deposits = generateDeposits( cfg, diff --git a/beacon_chain/validators/keystore_management.nim b/beacon_chain/validators/keystore_management.nim index 920a968ec..2514815c7 100644 --- a/beacon_chain/validators/keystore_management.nim +++ b/beacon_chain/validators/keystore_management.nim @@ -154,10 +154,9 @@ proc checkAndCreateDataDir*(dataDir: string): bool = new_permissions = requiredPerms.toOct(4) return false else: - let res = secureCreatePath(dataDir) - if res.isErr(): - fatal "Could not create data directory", data_dir = dataDir, - errorMsg = ioErrorMsg(res.error), errorCode = $res.error + if (let res = secureCreatePath(dataDir); res.isErr): + fatal "Could not create data directory", + path = dataDir, err = ioErrorMsg(res.error), errorCode = $res.error return false elif defined(windows): let amask = {AccessFlags.Read, AccessFlags.Write, AccessFlags.Execute} @@ -165,18 +164,17 @@ proc checkAndCreateDataDir*(dataDir: string): bool = let cres = checkCurrentUserOnlyACL(dataDir) if cres.isErr(): fatal "Could not check data folder's ACL", - data_dir = dataDir, errorCode = $cres.error, + path = dataDir, errorCode = $cres.error, errorMsg = ioErrorMsg(cres.error) return false else: if cres.get() == false: - fatal "Data folder has insecure ACL", data_dir = dataDir + fatal "Data folder has insecure ACL", path = dataDir return false else: - let res = secureCreatePath(dataDir) - if res.isErr(): - fatal "Could not create data folder", data_dir = dataDir, - errorMsg = ioErrorMsg(res.error), errorCode = $res.error + if (let res = secureCreatePath(dataDir); res.isErr): + fatal "Could not create data folder", + path = dataDir, err = ioErrorMsg(res.error), errorCode = $res.error return false else: fatal "Unsupported operation system"