Fix: Simplify main 'lab_commands' function#3464
Open
ipspace wants to merge 1 commit into
Open
Conversation
* 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
There was a problem hiding this comment.
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
debugcommand dispatch path fromlab_commands. - Adds
loading_error()helper and routes import/entry-point failures througherror_and_exit(). - Attempts to distinguish “unknown command” from “import failed inside a valid command module”.
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 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}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3449