Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better errors for missing executable
When trying to run a missing executable (e.g. developer forgot to installed a required tool) we logged a generic error that makes it harder to understand and the debug the issue: $ addons/velero/start velero Deploying velero Traceback (most recent call last): File "/home/nsoffer/src/ramen/test/addons/velero/start", line 38, in <module> deploy(cluster) File "/home/nsoffer/src/ramen/test/addons/velero/start", line 16, in deploy for line in commands.watch( File "/home/nsoffer/src/ramen/test/drenv/commands.py", line 96, in watch with subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.11/subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib64/python3.11/subprocess.py", line 1950, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'velero' There is no information on the code code that failed inside the script, and in particular, the command we tried to run. This is caused by not handling the error when subprocess.Popen() fail to execute the child process. Now we raise the standard `commands.Error`, preserving the traceback from the underlying error. Example error with this change: $ addons/velero/start velero Deploying velero Traceback (most recent call last): File "/home/nsoffer/src/ramen/test/addons/velero/start", line 38, in <module> deploy(cluster) File "/home/nsoffer/src/ramen/test/addons/velero/start", line 16, in deploy for line in commands.watch( File "/home/nsoffer/src/ramen/test/drenv/commands.py", line 119, in watch raise Error(args, f"Could not execute: {e}").with_exception(e) File "/home/nsoffer/src/ramen/test/drenv/commands.py", line 111, in watch p = subprocess.Popen( ^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.11/subprocess.py", line 1026, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib64/python3.11/subprocess.py", line 1950, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) drenv.commands.Error: Command failed: command: ('velero', 'install', '--provider=aws', '--plugins=velero/velero-plugin-for-aws:v1.2.1', '--bucket=bucket', '--secret-file=credentials.conf', '--use-volume-snapshots=false', '--backup-location-config=region=minio,s3ForcePathStyle=true,s3Url=http://192.168.39.8:30000', '--kubecontext=velero', '--wait') error: Could not execute: [Errno 2] No such file or directory: 'velero' Signed-off-by: Nir Soffer <nsoffer@redhat.com>
- Loading branch information