From de77ade90dd0ef44c9ac71b51ad02625c5fdeebb Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Fri, 24 Mar 2023 01:49:28 +0000 Subject: [PATCH] fix: add detail to exc only if brownie is connected --- dank_mids/helpers.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dank_mids/helpers.py b/dank_mids/helpers.py index af10a7c8..b8f783a4 100644 --- a/dank_mids/helpers.py +++ b/dank_mids/helpers.py @@ -24,8 +24,12 @@ def setup_dank_w3(async_w3: Web3) -> Web3: async_w3.middleware_onion.add(geth_poa_middleware) return async_w3 except ValueError as e: - if str(e) == "You can't add the same un-named instance twice": - raise ValueError("You can't add the same un-named instance twice. If you're calling 'setup_dank_w3' manually you may be better served by importing the pre-configured dank_web3 object from dank_mids.helpers.") + try: + from brownie import network + except ImportError: + raise e + if str(e) == "You can't add the same un-named instance twice" and network.is_connected(): + raise ValueError("You can't add the same un-named instance twice. If you're using brownie and you're calling 'setup_dank_w3' manually you may be better served by importing the pre-configured dank_web3 object from dank_mids.helpers.") raise e def setup_dank_w3_from_sync(sync_w3: Web3) -> Web3: