napalm-automation-community / napalm-sros

NAPALM driver for Nokia SR OS
Apache License 2.0
17 stars 17 forks source link

Exceptions are not re-raised #45

Open omron93 opened 2 years ago

omron93 commented 2 years ago

Inspecting the sros.py code I can see that in multiple places the exception is caught for logging the exception into log. But the exception is not re-raised, so it's logged but then the code continues in processing.

This is quite misleading and hard to properly integrate the sros driver into larger projects (the same applies to having prints in the driver which can't be "suppressed" from the application - the logging is configurable, the prints not). So I can see issues like

Error in opening netconf connection : Could not open socket to edge3-uat.linx.net:830
Error in method get config : 'NoneType' object has no attribute 'get_config'
Traceback (most recent call last):
  File "/home/marek/.local/bin/pysros", line 33, in <module>
    sys.exit(load_entry_point('pysros==0.0.4', 'console_scripts', 'pysros')())
  File "/home/marek/.local/lib/python3.8/site-packages/pysros/command_line.py", line 17, in wrapper
    func()
  File "/home/marek/.local/lib/python3.8/site-packages/pysros/command_line.py", line 170, in main
    running.write(result['running'])
TypeError: 'NoneType' object is not subscriptable

The reason for the failure is that the device is unreachable, but TypeError: 'NoneType' object is not subscriptable is completely unrelated and very misleading. That's even harder to debug when using the sros driver with projects like napalm-ansible because it doesn't show the printed command but just fails with 'NoneType' object has no attribute 'edit_config' :-)

Please re-raise the exceptions as that's the standard behaviour and the "application" should handle those issues not to have them suppressed in "library".