From 0a407903c077dcc88ce98dccbe698f1803685d34 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 26 Aug 2024 15:40:24 -0400 Subject: [PATCH 1/3] fix path bug --- bbot/core/helpers/command.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bbot/core/helpers/command.py b/bbot/core/helpers/command.py index 7283291fc8..a13f8b29d5 100644 --- a/bbot/core/helpers/command.py +++ b/bbot/core/helpers/command.py @@ -3,9 +3,9 @@ import logging import traceback from signal import SIGINT -from subprocess import CompletedProcess, CalledProcessError +from subprocess import CompletedProcess, CalledProcessError, SubprocessError -from .misc import smart_decode, smart_encode +from .misc import smart_decode, smart_encode, which log = logging.getLogger("bbot.core.helpers.command") @@ -276,6 +276,17 @@ def _prepare_command_kwargs(self, command, kwargs): command = command[0] command = [str(s) for s in command] + if not command: + raise SubprocessError("Must specify a command") + + # use full path of binary, if not already specified + binary = command[0] + if not "/" in binary: + binary_full_path = which(command[0]) + if binary_full_path is None: + raise SubprocessError(f'Command "{binary}" was not found') + command[0] = binary_full_path + env = kwargs.get("env", os.environ) if sudo and os.geteuid() != 0: self.depsinstaller.ensure_root() From d3922c2c75e379cd7542cce6febed0cb40c3801a Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 26 Aug 2024 16:13:50 -0400 Subject: [PATCH 2/3] fix tests --- bbot/core/helpers/command.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bbot/core/helpers/command.py b/bbot/core/helpers/command.py index a13f8b29d5..82e0aedfc5 100644 --- a/bbot/core/helpers/command.py +++ b/bbot/core/helpers/command.py @@ -182,7 +182,11 @@ async def _spawn_proc(self, *command, **kwargs): >>> _spawn_proc("ls", "-l", input="data") (, "data", ["ls", "-l"]) """ - command, kwargs = self._prepare_command_kwargs(command, kwargs) + try: + command, kwargs = self._prepare_command_kwargs(command, kwargs) + except SubprocessError as e: + log.warning(e) + return None, None, None _input = kwargs.pop("input", None) if _input is not None: if kwargs.get("stdin") is not None: From f652f73171a8d98d9cbbd5d2804b58783e50eb8c Mon Sep 17 00:00:00 2001 From: TheTechromancer <20261699+TheTechromancer@users.noreply.github.com> Date: Mon, 26 Aug 2024 23:01:53 -0400 Subject: [PATCH 3/3] Update command.py --- bbot/core/helpers/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bbot/core/helpers/command.py b/bbot/core/helpers/command.py index 82e0aedfc5..6f43a401db 100644 --- a/bbot/core/helpers/command.py +++ b/bbot/core/helpers/command.py @@ -286,7 +286,7 @@ def _prepare_command_kwargs(self, command, kwargs): # use full path of binary, if not already specified binary = command[0] if not "/" in binary: - binary_full_path = which(command[0]) + binary_full_path = which(binary) if binary_full_path is None: raise SubprocessError(f'Command "{binary}" was not found') command[0] = binary_full_path