From 38dc2e3b065ed30834e4e8ba2b47de20537f4e0b Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Wed, 29 Jul 2020 19:37:05 +0300 Subject: [PATCH 1/2] refactor: adjust kwargs, add error_dict attribute --- solcx/exceptions.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/solcx/exceptions.py b/solcx/exceptions.py index 202149a..95a8f71 100644 --- a/solcx/exceptions.py +++ b/solcx/exceptions.py @@ -1,27 +1,27 @@ -from typing import Optional - -DEFAULT_MESSAGE = "An error occurred during execution" +from typing import Dict, List class SolcError(Exception): - message = DEFAULT_MESSAGE + message = "An error occurred during execution" def __init__( self, - command: list, - return_code: Optional[int], - stdin_data: Optional[str], - stdout_data: Optional[str], - stderr_data: Optional[str], - message: Optional[str] = None, + message: str = None, + command: List = None, + return_code: int = None, + stdin_data: str = None, + stdout_data: str = None, + stderr_data: str = None, + error_dict: Dict = None, ) -> None: if message is not None: self.message = message - self.command = command + self.command = command or [] self.return_code = return_code self.stdin_data = stdin_data self.stderr_data = stderr_data self.stdout_data = stdout_data + self.error_dict = error_dict def __str__(self) -> str: return ( From 8318273f5a0ba00927d5d19ea6aaabbe5a25cc68 Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Wed, 29 Jul 2020 19:37:30 +0300 Subject: [PATCH 2/2] refactor: adjust exception kwargs, pass error dict on failed json compile --- solcx/main.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/solcx/main.py b/solcx/main.py index 2e94611..c092553 100644 --- a/solcx/main.py +++ b/solcx/main.py @@ -155,7 +155,6 @@ def compile_files( raise ContractsNotFound( command=command, return_code=proc.returncode, - stdin_data=None, stdout_data=stdoutdata, stderr_data=stderrdata, ) @@ -174,11 +173,8 @@ def compile_standard( ) -> Dict: if not input_data.get("sources") and not allow_empty: raise ContractsNotFound( - command=[], - return_code=None, + "Input JSON does not contain any sources", stdin_data=json.dumps(input_data, sort_keys=True, indent=2), - stdout_data=None, - stderr_data=None, ) if solc_binary is None: @@ -206,12 +202,13 @@ def compile_standard( ) ) raise SolcError( - command, - proc.returncode, - json.dumps(input_data), - stdoutdata, - stderrdata, - message=error_message, + error_message, + command=command, + return_code=proc.returncode, + stdin_data=json.dumps(input_data), + stdout_data=stdoutdata, + stderr_data=stderrdata, + error_dict=compiler_output["errors"], ) return compiler_output