better error messages on directory creation failure (#3536)

This commit is contained in:
Jacek Sieka 2022-03-22 18:06:21 +01:00 committed by GitHub
parent e7d017b50c
commit 70270eeabe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 33 deletions

View File

@ -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()

View File

@ -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].} =

View File

@ -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(

View File

@ -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,

View File

@ -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"