Skip to content

Commit

Permalink
fix: remove decode inside _call
Browse files Browse the repository at this point in the history
Fixes a bug where the script would throw when `check_output` throws an error, since the returned `stderr` would be a str instead of bytes.
  • Loading branch information
jedel1043 authored and NucciTheBoss committed Sep 10, 2024
1 parent d317d83 commit 4e5e870
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/charms/hpc_libs/v0/slurm_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def _call(cmd: str, *args: str, stdin: Optional[str] = None) -> str:
return subprocess.check_output(cmd, input=stdin, stderr=subprocess.PIPE, text=True).strip()
except subprocess.CalledProcessError as e:
_logger.error(f"`{' '.join(cmd)}` failed")
_logger.error(f"stderr: {e.stderr.decode()}")
raise SlurmOpsError(f"command {cmd[0]} failed. reason:\n{e.stderr.decode()}")
_logger.error(f"stderr: {e.stderr}")
raise SlurmOpsError(f"command {cmd[0]} failed. reason:\n{e.stderr}")


def _snap(*args) -> str:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_slurm_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_version_not_installed(self, subcmd) -> None:

def test_call_error(self, subcmd) -> None:
"""Test that `slurm_ops` propagates errors when a command fails."""
subcmd.side_effect = subprocess.CalledProcessError(-1, cmd=[""], stderr=b"error")
subcmd.side_effect = subprocess.CalledProcessError(-1, cmd=[""], stderr="error")
with self.assertRaises(slurm.SlurmOpsError):
self.manager.install()

Expand Down

0 comments on commit 4e5e870

Please sign in to comment.