From faacdf55805dc50fbd678da386fdd66a8f971e76 Mon Sep 17 00:00:00 2001 From: Ivan Pepelnjak Date: Fri, 18 Oct 2024 09:16:54 +0200 Subject: [PATCH] Bug fix: abort on fatal initialization errors * The netsim initialization module failed to abort after reporting incorrect python-box version because sys.exit was executed inside the try block * Netlab reported a failure to import netsim but then tried to continue like nothing happened --- netlab | 2 ++ netsim/__init__.py | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/netlab b/netlab index 29640d44d..2e983e18c 100755 --- a/netlab +++ b/netlab @@ -2,11 +2,13 @@ # # Main netsim-tools CLI command # +import sys try: import netsim import netsim.cli except: print("Cannot import netsim Python module, netlab installation is broken") + sys.exit(1) netsim.cli.lab_commands(__file__) diff --git a/netsim/__init__.py b/netsim/__init__.py index 69fd8ed38..34f8b7e48 100755 --- a/netsim/__init__.py +++ b/netsim/__init__.py @@ -4,11 +4,17 @@ __version__ = "1.9.2-dev1" +abort = False + try: import box if box.__version__ < '7.2.0': # netlab needs Python Box version 7.0 or higher print("FATAL ERROR: python-box version 7.2.0 or higher required, use 'pip3 install --upgrade python-box' to install") - sys.exit(1) + abort = True + except: # box is not installed, something else is bound to fail ;) pass + +if abort: + sys.exit(1)