Skip to content

Commit

Permalink
fix error when mc admin response has a trailing newline (#1099)
Browse files Browse the repository at this point in the history
To avoid empty strings after splitting `proc.stdout`, `splitlines` is used
instead of `split`.

To avoid errors when `proc.stdout` itself is empty, an additional guard has been
added. In this case, an empty list or dictionary is returned, depending on
`multiline`.

Also, `text=True` is passed `subprocess.run` to ensure `proc.stdout` is a string
and not bytes object.
  • Loading branch information
bo5o authored May 24, 2021
1 parent df3e895 commit 0e5a62e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion minio/minioadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ def _run(self, args, multiline=False):
capture_output=True,
timeout=self._timeout,
check=True,
text=True,
)
if not proc.stdout:
return [] if multiline else {}
if multiline:
return [json.loads(line) for line in proc.stdout.split("\n")]
return [json.loads(line) for line in proc.stdout.splitlines()]
return json.loads(proc.stdout)

def service_restart(self):
Expand Down

0 comments on commit 0e5a62e

Please sign in to comment.