Skip to content

Fix: Simplify main 'lab_commands' function#3464

Open
ipspace wants to merge 1 commit into
devfrom
lab-commands
Open

Fix: Simplify main 'lab_commands' function#3464
ipspace wants to merge 1 commit into
devfrom
lab-commands

Conversation

@ipspace

@ipspace ipspace commented Jun 8, 2026

Copy link
Copy Markdown
Owner
  • Removes the 'debug' argument (it was used only to use the modules without the try/except block)
  • Try to identify whether a module loading error is caused by an invalid command name or some other import error
  • Give some troubleshooting instructions in case netlab crashes due to corrupted source code

Closes #3449

* Removes the 'debug' argument (it was used only to use the modules
  without the try/except block)
* Try to identify whether a module loading error is caused by an
  invalid command name or some other import error
* Give some troubleshooting instructions in case netlab crashes due
  to corrupted source code

Closes #3449

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Simplifies the netsim.cli command dispatcher by removing the legacy debug path, centralizing module import failure handling, and improving user-facing troubleshooting hints when a CLI command module fails to load.

Changes:

  • Removes the legacy debug command dispatch path from lab_commands.
  • Adds loading_error() helper and routes import/entry-point failures through error_and_exit().
  • Attempts to distinguish “unknown command” from “import failed inside a valid command module”.

Comment thread netsim/cli/__init__.py
Comment on lines +536 to +543
except ModuleNotFoundError as ex:
if modname in str(ex):
error_and_exit(
f'Unknown command {cmd}',
module='netlab',
more_hints=[ "Use 'netlab help' to get the list of valid commands" ])
else:
loading_error(ex,modname)
Comment thread netsim/cli/__init__.py
Comment on lines 529 to +533
if cmd in ['-h','--help']:
cmd = 'help'

if cmd == 'debug':
arg_start = 3
cmd = sys.argv[2]
mod = importlib.import_module("."+sys.argv[2],__name__)
elif quick_commands.get(cmd,None):
quick_commands[cmd](sys.argv[arg_start:])
return

NETLAB_COMMAND = cmd
modname = f"{__name__}.{cmd}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Cleanup netsim.cli.lab_commands()

2 participants