Add RegistrarDoesNotExist error and raise in _read_registrar_file:

pull/224/merge^2
tuxxy 2018-04-12 19:49:15 -06:00
parent 85fe1df193
commit 8c4ce6fd64
1 changed files with 11 additions and 4 deletions

View File

@ -11,9 +11,14 @@ from web3.providers.tester import EthereumTesterProvider
from nkms.blockchain.eth.sol.compile import compile_interfaces, SolidityConfig
_DEFAULT_CONFIGURATION_DIR = os.path.join(str(Path.home()), '.nucypher')
class RegistrarDoesNotExist(FileNotFoundError):
pass
def _write_registrar_file(registrar_data: dict, registrar_filepath: str) -> None:
"""
Writes the registrar data dict as JSON to the registrar file. If no
@ -35,11 +40,13 @@ def _read_registrar_file(registrar_filepath: str) -> dict:
this function first to get the current state to append to the dict or
modify it because _write_registrar_file overwrites the file.
"""
with open(registrar_filepath, 'r') as registrar_file:
try:
try:
with open(registrar_filepath, 'r') as registrar_file:
registrar_data = json.loads(registrar_file.read())
except json.decoder.JSONDecodeError:
registrar_data = dict()
except json.decoder.JSONDecodeError:
registrar_data = dict()
except FileNotFoundError:
raise RegistrarDoesNotExist("No Registrar exists at this filepath.")
return registrar_data