Skip to content

Commit

Permalink
Merge pull request #351 from crytic/dev-fix-error-decode
Browse files Browse the repository at this point in the history
Decode debugging and error output with backslashreplace
  • Loading branch information
montyly authored Jan 10, 2023
2 parents fe7aadf + 719ffe3 commit a2662cb
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 21 deletions.
4 changes: 2 additions & 2 deletions crytic_compile/crytic_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,8 @@ def _run_custom_build(custom_build: str) -> None:
with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as process:
stdout_bytes, stderr_bytes = process.communicate()
stdout, stderr = (
stdout_bytes.decode(),
stderr_bytes.decode(),
stdout_bytes.decode(errors="backslashreplace"),
stderr_bytes.decode(errors="backslashreplace"),
) # convert bytestrings to unicode strings

LOGGER.info(stdout)
Expand Down
4 changes: 2 additions & 2 deletions crytic_compile/platform/brownie.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
) as process:
stdout_bytes, stderr_bytes = process.communicate()
stdout, stderr = (
stdout_bytes.decode(),
stderr_bytes.decode(),
stdout_bytes.decode(errors="backslashreplace"),
stderr_bytes.decode(errors="backslashreplace"),
) # convert bytestrings to unicode strings

LOGGER.info(stdout)
Expand Down
4 changes: 2 additions & 2 deletions crytic_compile/platform/buidler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:

stdout_bytes, stderr_bytes = process.communicate()
stdout, stderr = (
stdout_bytes.decode(),
stderr_bytes.decode(),
stdout_bytes.decode(errors="backslashreplace"),
stderr_bytes.decode(errors="backslashreplace"),
) # convert bytestrings to unicode strings

LOGGER.info(stdout)
Expand Down
4 changes: 2 additions & 2 deletions crytic_compile/platform/embark.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
# pylint: disable=raise-missing-from
raise InvalidCompilation(error)
stdout, stderr = process.communicate()
LOGGER.info("%s\n", stdout.decode())
LOGGER.info("%s\n", stdout.decode(errors="backslashreplace"))
if stderr:
# Embark might return information to stderr, but compile without issue
LOGGER.error("%s", stderr.decode())
LOGGER.error("%s", stderr.decode(errors="backslashreplace"))
infile = os.path.join(self._target, "crytic-export", "contracts-embark.json")
if not os.path.isfile(infile):
raise InvalidCompilation(
Expand Down
4 changes: 2 additions & 2 deletions crytic_compile/platform/etherlime.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def _run_etherlime(target: str, npx_disable: bool, compile_arguments: Optional[s
) as process:
stdout_bytes, stderr_bytes = process.communicate()
stdout, stderr = (
stdout_bytes.decode(),
stderr_bytes.decode(),
stdout_bytes.decode(errors="backslashreplace"),
stderr_bytes.decode(errors="backslashreplace"),
) # convert bytestrings to unicode strings

LOGGER.info(stdout)
Expand Down
4 changes: 2 additions & 2 deletions crytic_compile/platform/foundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:

stdout_bytes, stderr_bytes = process.communicate()
stdout, stderr = (
stdout_bytes.decode(),
stderr_bytes.decode(),
stdout_bytes.decode(errors="backslashreplace"),
stderr_bytes.decode(errors="backslashreplace"),
) # convert bytestrings to unicode strings

LOGGER.info(stdout)
Expand Down
6 changes: 3 additions & 3 deletions crytic_compile/platform/hardhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:

stdout_bytes, stderr_bytes = process.communicate()
stdout, stderr = (
stdout_bytes.decode(),
stderr_bytes.decode(),
stdout_bytes.decode(errors="backslashreplace"),
stderr_bytes.decode(errors="backslashreplace"),
) # convert bytestrings to unicode strings

LOGGER.info(stdout)
Expand Down Expand Up @@ -308,7 +308,7 @@ def _run_hardhat_console(self, base_cmd: List[str], command: str) -> Optional[st
stdout_bytes, stderr_bytes = process.communicate(command.encode("utf-8"))
stdout, stderr = (
stdout_bytes.decode(),
stderr_bytes.decode(),
stderr_bytes.decode(errors="backslashreplace"),
)

if stderr:
Expand Down
2 changes: 1 addition & 1 deletion crytic_compile/platform/solc_standard_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def run_solc_standard_json(
stdout_b, stderr_b = process.communicate(json.dumps(solc_input).encode("utf-8"))
stdout, stderr = (
stdout_b.decode(),
stderr_b.decode(),
stderr_b.decode(errors="backslashreplace"),
) # convert bytestrings to unicode strings

solc_json_output = json.loads(stdout)
Expand Down
4 changes: 2 additions & 2 deletions crytic_compile/platform/truffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:

stdout_bytes, stderr_bytes = process.communicate()
stdout, stderr = (
stdout_bytes.decode(),
stderr_bytes.decode(),
stdout_bytes.decode(errors="backslashreplace"),
stderr_bytes.decode(errors="backslashreplace"),
) # convert bytestrings to unicode strings

if truffle_overwrite_config:
Expand Down
4 changes: 2 additions & 2 deletions crytic_compile/platform/waffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
) as process:
stdout, stderr = process.communicate()
if stdout:
LOGGER.info(stdout.decode())
LOGGER.info(stdout.decode(errors="backslashreplace"))
if stderr:
LOGGER.error(stderr.decode())
LOGGER.error(stderr.decode(errors="backslashreplace"))
except OSError as error:
# pylint: disable=raise-missing-from
raise InvalidCompilation(error)
Expand Down
5 changes: 4 additions & 1 deletion crytic_compile/utils/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def run(
LOGGER.error("Could not execute `%s`, is it installed and in PATH?", cmd[0])
except subprocess.CalledProcessError as e:
LOGGER.error("'%s' returned non-zero exit code %d", cmd[0], e.returncode)
stdout, stderr = (e.stdout.decode().strip(), e.stderr.decode().strip())
stdout, stderr = (
e.stdout.decode(errors="backslashreplace").strip(),
e.stderr.decode(errors="backslashreplace").strip(),
)
if stdout:
LOGGER.error("\nstdout: ".join(stdout.split("\n")))
if stderr:
Expand Down

0 comments on commit a2662cb

Please sign in to comment.