From 216afac3f271b345c115d8777b1a6ad671bebc4f Mon Sep 17 00:00:00 2001 From: a-bad-dev <244852891+a-bad-dev@users.noreply.github.com> Date: Fri, 20 Feb 2026 23:28:56 -0400 Subject: [PATCH] Fix invalid UTF-8 bytes in output crashing the script --- main.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 7455e16..15ca5ce 100644 --- a/main.py +++ b/main.py @@ -106,6 +106,7 @@ class IRC2BASH: # command_list = [] + command_noescapes = command for letter in command: match letter: case "\\": @@ -126,15 +127,19 @@ class IRC2BASH: print(f"{channel}: <{username}> {command}") os.system(f"/bin/bash -c \"{command}\" >/tmp/.command 2>&1") - with open("/tmp/.command", "r") as f: - output = f.read() - - output = output.strip() - print(output) - output = output.split("\n") - for line in output: - IRC2BASH.send(f"PRIVMSG {IRC2BASH.chan} :{line}") - time.sleep(0.75) + try: + with open("/tmp/.command", "r") as f: + output = f.read() + output = output.strip() + print(output) + output = output.split("\n") + for line in output: + IRC2BASH.send(f"PRIVMSG {IRC2BASH.chan} :{line}") + time.sleep(0.75) + + except UnicodeDecodeError: + print(f"UnicodeDecodeError: invalid bytes, caused by: {command_noescapes}") + IRC2BASH.send(f"PRIVMSG {IRC2BASH.chan} :Invalid bytes in response.") if __name__ == "__main__": IRC2BASH.main()