Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor exceptions #103

Merged
merged 2 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions solcx/exceptions.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
19 changes: 8 additions & 11 deletions solcx/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ def compile_files(
raise ContractsNotFound(
command=command,
return_code=proc.returncode,
stdin_data=None,
stdout_data=stdoutdata,
stderr_data=stderrdata,
)
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down