From f281c7aeaaab6b26312b53d2124b656937cabaf5 Mon Sep 17 00:00:00 2001 From: "Afshin T. Darian" Date: Mon, 19 Jul 2021 21:58:41 +0100 Subject: [PATCH] Fix handling of error output --- jupyter_releaser/lib.py | 2 +- jupyter_releaser/tests/test_cli.py | 4 ++-- jupyter_releaser/util.py | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/jupyter_releaser/lib.py b/jupyter_releaser/lib.py index 92c23c85..d21159c2 100644 --- a/jupyter_releaser/lib.py +++ b/jupyter_releaser/lib.py @@ -384,7 +384,7 @@ def publish_assets(dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, use_checkou try: util.run(f"{npm_cmd} {name}", cwd=dist_dir, quiet=True) except CalledProcessError as e: - stderr = e.stderr.decode("utf-8") + stderr = e.stderr if ( "EPUBLISHCONFLICT" in stderr or "previously published versions" in stderr diff --git a/jupyter_releaser/tests/test_cli.py b/jupyter_releaser/tests/test_cli.py index b080d533..43469dda 100644 --- a/jupyter_releaser/tests/test_cli.py +++ b/jupyter_releaser/tests/test_cli.py @@ -530,7 +530,7 @@ def wrapped(cmd, **kwargs): called += 1 if called == 0: err = CalledProcessError(1, "foo") - err.stderr = "EPUBLISHCONFLICT".encode("UTF-8") + err.stderr = "EPUBLISHCONFLICT" raise err mock_run = mocker.patch("jupyter_releaser.util.run", wraps=wrapped) @@ -559,7 +559,7 @@ def wrapped(cmd, **kwargs): if cmd.startswith("npm publish --dry-run"): called += 1 err = CalledProcessError(1, "foo") - err.stderr = "previously published versions".encode("UTF-8") + err.stderr = "previously published versions" raise err mocker.patch("jupyter_releaser.util.run", wraps=wrapped) diff --git a/jupyter_releaser/util.py b/jupyter_releaser/util.py index 0c3ae300..fe4217ae 100644 --- a/jupyter_releaser/util.py +++ b/jupyter_releaser/util.py @@ -82,9 +82,11 @@ def _run_win(cmd, **kwargs): log(output) return output except CalledProcessError as e: + e.output = e.output.decode("utf-8") if quiet: - log("stderr:\n", e.stderr.decode("utf-8").strip(), "\n\n") - log("stdout:\n", e.output.decode("utf-8").strip(), "\n\n") + e.stderr = e.stderr.decode("utf-8") + log("stderr:\n", e.stderr.strip(), "\n\n") + log("stdout:\n", e.output.strip(), "\n\n") raise e