Skip to content

Commit a2662cb

Browse files
authored
Merge pull request #351 from crytic/dev-fix-error-decode
Decode debugging and error output with backslashreplace
2 parents fe7aadf + 719ffe3 commit a2662cb

File tree

11 files changed

+24
-21
lines changed

11 files changed

+24
-21
lines changed

crytic_compile/crytic_compile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,8 @@ def _run_custom_build(custom_build: str) -> None:
547547
with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as process:
548548
stdout_bytes, stderr_bytes = process.communicate()
549549
stdout, stderr = (
550-
stdout_bytes.decode(),
551-
stderr_bytes.decode(),
550+
stdout_bytes.decode(errors="backslashreplace"),
551+
stderr_bytes.decode(errors="backslashreplace"),
552552
) # convert bytestrings to unicode strings
553553

554554
LOGGER.info(stdout)

crytic_compile/platform/brownie.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
6363
) as process:
6464
stdout_bytes, stderr_bytes = process.communicate()
6565
stdout, stderr = (
66-
stdout_bytes.decode(),
67-
stderr_bytes.decode(),
66+
stdout_bytes.decode(errors="backslashreplace"),
67+
stderr_bytes.decode(errors="backslashreplace"),
6868
) # convert bytestrings to unicode strings
6969

7070
LOGGER.info(stdout)

crytic_compile/platform/buidler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
8080

8181
stdout_bytes, stderr_bytes = process.communicate()
8282
stdout, stderr = (
83-
stdout_bytes.decode(),
84-
stderr_bytes.decode(),
83+
stdout_bytes.decode(errors="backslashreplace"),
84+
stderr_bytes.decode(errors="backslashreplace"),
8585
) # convert bytestrings to unicode strings
8686

8787
LOGGER.info(stdout)

crytic_compile/platform/embark.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
104104
# pylint: disable=raise-missing-from
105105
raise InvalidCompilation(error)
106106
stdout, stderr = process.communicate()
107-
LOGGER.info("%s\n", stdout.decode())
107+
LOGGER.info("%s\n", stdout.decode(errors="backslashreplace"))
108108
if stderr:
109109
# Embark might return information to stderr, but compile without issue
110-
LOGGER.error("%s", stderr.decode())
110+
LOGGER.error("%s", stderr.decode(errors="backslashreplace"))
111111
infile = os.path.join(self._target, "crytic-export", "contracts-embark.json")
112112
if not os.path.isfile(infile):
113113
raise InvalidCompilation(

crytic_compile/platform/etherlime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def _run_etherlime(target: str, npx_disable: bool, compile_arguments: Optional[s
5757
) as process:
5858
stdout_bytes, stderr_bytes = process.communicate()
5959
stdout, stderr = (
60-
stdout_bytes.decode(),
61-
stderr_bytes.decode(),
60+
stdout_bytes.decode(errors="backslashreplace"),
61+
stderr_bytes.decode(errors="backslashreplace"),
6262
) # convert bytestrings to unicode strings
6363

6464
LOGGER.info(stdout)

crytic_compile/platform/foundry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
8787

8888
stdout_bytes, stderr_bytes = process.communicate()
8989
stdout, stderr = (
90-
stdout_bytes.decode(),
91-
stderr_bytes.decode(),
90+
stdout_bytes.decode(errors="backslashreplace"),
91+
stderr_bytes.decode(errors="backslashreplace"),
9292
) # convert bytestrings to unicode strings
9393

9494
LOGGER.info(stdout)

crytic_compile/platform/hardhat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
7979

8080
stdout_bytes, stderr_bytes = process.communicate()
8181
stdout, stderr = (
82-
stdout_bytes.decode(),
83-
stderr_bytes.decode(),
82+
stdout_bytes.decode(errors="backslashreplace"),
83+
stderr_bytes.decode(errors="backslashreplace"),
8484
) # convert bytestrings to unicode strings
8585

8686
LOGGER.info(stdout)
@@ -308,7 +308,7 @@ def _run_hardhat_console(self, base_cmd: List[str], command: str) -> Optional[st
308308
stdout_bytes, stderr_bytes = process.communicate(command.encode("utf-8"))
309309
stdout, stderr = (
310310
stdout_bytes.decode(),
311-
stderr_bytes.decode(),
311+
stderr_bytes.decode(errors="backslashreplace"),
312312
)
313313

314314
if stderr:

crytic_compile/platform/solc_standard_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def run_solc_standard_json(
157157
stdout_b, stderr_b = process.communicate(json.dumps(solc_input).encode("utf-8"))
158158
stdout, stderr = (
159159
stdout_b.decode(),
160-
stderr_b.decode(),
160+
stderr_b.decode(errors="backslashreplace"),
161161
) # convert bytestrings to unicode strings
162162

163163
solc_json_output = json.loads(stdout)

crytic_compile/platform/truffle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
176176

177177
stdout_bytes, stderr_bytes = process.communicate()
178178
stdout, stderr = (
179-
stdout_bytes.decode(),
180-
stderr_bytes.decode(),
179+
stdout_bytes.decode(errors="backslashreplace"),
180+
stderr_bytes.decode(errors="backslashreplace"),
181181
) # convert bytestrings to unicode strings
182182

183183
if truffle_overwrite_config:

crytic_compile/platform/waffle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
160160
) as process:
161161
stdout, stderr = process.communicate()
162162
if stdout:
163-
LOGGER.info(stdout.decode())
163+
LOGGER.info(stdout.decode(errors="backslashreplace"))
164164
if stderr:
165-
LOGGER.error(stderr.decode())
165+
LOGGER.error(stderr.decode(errors="backslashreplace"))
166166
except OSError as error:
167167
# pylint: disable=raise-missing-from
168168
raise InvalidCompilation(error)

0 commit comments

Comments
 (0)