Skip to content

Commit

Permalink
Bug fix: abort on fatal initialization errors
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ipspace committed Oct 18, 2024
1 parent 57d39cf commit faacdf5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions netlab
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
8 changes: 7 additions & 1 deletion netsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit faacdf5

Please sign in to comment.