BstLabs / py-dynacli

DynaCLI is a cloud-friendly Python library for converting pure Python functions into Linux Shell commands.
https://bstlabs.github.io/py-dynacli/
MIT License
98 stars 5 forks source link

[BUG] Incorrect reporting when command module contains a compilation error #86

Open asterkin opened 2 years ago

asterkin commented 2 years ago

Describe the bug When a command module generates a compilation or run-time error an incorrect error message is printed, while -h option will print the correct one.

To Reproduce ./clvm connect caios-asher-dev-desktop will print "unrecognized argument caios-dev-asher-desktopt" or something like that if connect module generates an error. ./clvm -h will print a correct error message

Expected behavior correct error message in both cases

Screenshots asterkin@asterkin-ideacentre-AIO-510-23ISH:~/clvm$ ./clvm connect caios-dev-asher-desktop usage: clvm [-h] [-v] {connect,redirect} ... clvm: error: unrecognized arguments: caios-dev-asher-desktop asterkin@asterkin-ideacentre-AIO-510-23ISH:~/clvm$ ./clvm connect -h usage: clvm connect [-h]

optional arguments: -h, --help show this help message and exit asterkin@asterkin-ideacentre-AIO-510-23ISH:~/clvm$ ./clvm -h usage: clvm [-h] [-v] {connect,redirect} ...

Command Line Utility to connect or redirect ports to a Cloud Virtual Machine

positional arguments: {connect,redirect} connect [ERROR] failed to import connect - name 'atch_module' is not defined redirect [ERROR] failed to import redirect - name 'atch_module' is not defined

optional arguments: -h, --help show this help message and exit -v, --version show program's version number and exit

Extra info:

ShahriyarR commented 2 years ago

@asterkin please see my question below

Test results:

./testclinested -h
usage: testclinested [-h] [-v] {feature-A,feature-B,feature-C,feature-D,feature-F,feature-Z,service} ...

Sample DynaCLI Tool for nested package tests

positional arguments:
  {feature-A,feature-B,feature-C,feature-D,feature-F,feature-Z,service}
    feature-A           Top level package
    feature-B           Here we are going to use function shortcut directly importing it in __init__.py
    feature-C           Awesome
    feature-D           Imitating the import errors at module level
    feature-F           [ERROR] failed to import feature_F - No module named 'xxxx'
    feature-Z           For admin users
    service             This is an example of module feature

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit

We have feature-F which has an import error.

Getting help for this feature:

./testclinested feature-F -h
usage: testclinested feature-F [-h]

optional arguments:
  -h, --help  show this help message and exit

Running non-existing command:

/testclinested feature-F xxx
usage: testclinested [-h] [-v] {feature-A,feature-B,feature-C,feature-D,feature-F,feature-Z,service} ...
testclinested: error: unrecognized arguments: xxx

So basically this is because no xxx argument was registered with argparse.

What should we do in such a case? Show this import error for both -h and for actual command run?

asterkin commented 2 years ago

We need to distinguish between "module not found" and "module import failed due to internal import error"