From 4836f52a5dda3cc24710180c9854cc467869a664 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Tue, 6 Jul 2021 07:26:09 -0400 Subject: [PATCH] shell_command: ignore utf8 decode errors Also catch a potential KeyError when removing running commands. Signed-off-by: Eric Callahan --- moonraker/components/shell_command.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/moonraker/components/shell_command.py b/moonraker/components/shell_command.py index 86760b8..c63f565 100644 --- a/moonraker/components/shell_command.py +++ b/moonraker/components/shell_command.py @@ -70,7 +70,9 @@ class SCProcess(asyncio.subprocess.Process): if not output: break if fd == 2 and self.log_stderr: - logging.info(f"{self.program_name}: {output.decode()}") + logging.info( + f"{self.program_name}: " + f"{output.decode(errors='ignore')}") output = output.rstrip(b'\n') if output and cb is not None: cb(output) @@ -222,14 +224,15 @@ class ShellCommand: complete = not self.cancelled if self.log_stderr and stderr: logging.info( - f"{self.command[0]}: {stderr.decode()}") + f"{self.command[0]}: " + f"{stderr.decode(errors='ignore')}") if self._check_proc_success(complete, log_complete): self.factory.remove_running_command(self) - return stdout.decode().rstrip("\n") + return stdout.decode(errors='ignore').rstrip("\n") if stdout: logging.debug( f"Shell command '{self.name}' output:" - f"\n{stdout.decode()}") + f"\n{stdout.decode(errors='ignore')}") if self.cancelled and not timed_out: break retries -= 1 @@ -292,7 +295,10 @@ class ShellCommandFactory: self.running_commands.add(cmd) def remove_running_command(self, cmd: ShellCommand) -> None: - self.running_commands.remove(cmd) + try: + self.running_commands.remove(cmd) + except KeyError: + pass def build_shell_command(self, cmd: str,