better error message on invalid URL (fixes #4023) (#4024)

This commit is contained in:
Jacek Sieka 2022-08-26 17:47:55 +02:00 committed by GitHub
parent 66a5e88203
commit 91a1b4e0c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,7 +95,9 @@ proc doTrustedNodeSync*(
# When we don't have a head, we'll use the given checkpoint as head # When we don't have a head, we'll use the given checkpoint as head
FAR_FUTURE_SLOT FAR_FUTURE_SLOT
var client = RestClientRef.new(restUrl).get() var client = RestClientRef.new(restUrl).valueOr:
error "Cannot connect to server", url = restUrl, error = error
quit 1
proc downloadBlock(slot: Slot): proc downloadBlock(slot: Slot):
Future[Option[ref ForkedSignedBeaconBlock]] {.async.} = Future[Option[ref ForkedSignedBeaconBlock]] {.async.} =
@ -107,7 +109,9 @@ proc doTrustedNodeSync*(
except CatchableError as exc: except CatchableError as exc:
lastError = exc lastError = exc
warn "Retrying download of block", slot, err = exc.msg warn "Retrying download of block", slot, err = exc.msg
client = RestClientRef.new(restUrl).get() client = RestClientRef.new(restUrl).valueOr:
error "Cannot connect to server", url = restUrl, error = error
quit 1
error "Unable to download block - backfill incomplete, but will resume when you start the beacon node", error "Unable to download block - backfill incomplete, but will resume when you start the beacon node",
slot, error = lastError.msg, url = client.address slot, error = lastError.msg, url = client.address
@ -115,27 +119,25 @@ proc doTrustedNodeSync*(
quit 1 quit 1
let let
dbGenesis = db.getGenesisBlock() localGenesisRoot = db.getGenesisBlock().valueOr:
localGenesisRoot = if dbGenesis.isSome(): let genesisState =
dbGenesis.get() if genesisState != nil:
else: genesisState
let genesisState = if genesisState != nil: else:
genesisState notice "Downloading genesis state", restUrl
else: let state = try:
notice "Downloading genesis state", restUrl await client.getStateV2(
let state = try: StateIdent.init(StateIdentType.Genesis), cfg)
await client.getStateV2( except CatchableError as exc:
StateIdent.init(StateIdentType.Genesis), cfg) error "Unable to download genesis state",
except CatchableError as exc: error = exc.msg, restUrl
error "Unable to download genesis state", quit 1
error = exc.msg, restUrl
quit 1
if isNil(state): if isNil(state):
error "Server is missing genesis state", error "Server is missing genesis state",
restUrl restUrl
quit 1 quit 1
state state
withState(genesisState[]): withState(genesisState[]):
info "Writing genesis state", info "Writing genesis state",