From e17ab9d0003f7e9edf730ac8b409c2d6273e156e Mon Sep 17 00:00:00 2001 From: marie-fourier Date: Thu, 21 Sep 2023 14:53:28 +0500 Subject: [PATCH] handle network error during fetching chain id --- packages/cli/src/cmds/node/handler.ts | 4 ++++ packages/cli/src/cmds/standalone/handler.ts | 4 ++++ packages/executor/src/config.ts | 8 ++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/cmds/node/handler.ts b/packages/cli/src/cmds/node/handler.ts index c6c6430b..9c167c8d 100644 --- a/packages/cli/src/cmds/node/handler.ts +++ b/packages/cli/src/cmds/node/handler.ts @@ -34,6 +34,10 @@ export async function nodeHandler(args: IGlobalArgs): Promise { redirectRpc: params.redirectRpc, }); } catch (err) { + if (err instanceof Error && err.message.indexOf("chain id") > -1) { + logger.error(err.message); + return; + } logger.info("Config file not found. Proceeding with env vars..."); config = await Config.init({ networks: {}, diff --git a/packages/cli/src/cmds/standalone/handler.ts b/packages/cli/src/cmds/standalone/handler.ts index b9840a98..00ebca44 100644 --- a/packages/cli/src/cmds/standalone/handler.ts +++ b/packages/cli/src/cmds/standalone/handler.ts @@ -41,6 +41,10 @@ export async function bundlerHandler( redirectRpc, }); } catch (err) { + if (err instanceof Error && err.message.indexOf("chain id") > -1) { + logger.error(err.message); + return; + } logger.debug("Config file not found. Proceeding with env vars..."); config = await Config.init({ networks: {}, diff --git a/packages/executor/src/config.ts b/packages/executor/src/config.ts index 8884a534..fc8e3013 100644 --- a/packages/executor/src/config.ts +++ b/packages/executor/src/config.ts @@ -79,8 +79,12 @@ export class Config { if (!provider) { throw new Error(`No provider for ${networkName}`); } - const network = await provider.getNetwork(); - this.supportedNetworks[networkName] = network.chainId; + try { + const network = await provider.getNetwork(); + this.supportedNetworks[networkName] = network.chainId; + } catch (err) { + throw new Error(`Could not fetch chain id for ${networkName}`); + } } }