fortinet-ansible-dev / ansible-galaxy-fortios-collection

GNU General Public License v3.0
85 stars 49 forks source link

Wrong handling of Exceptions / TypeError: exceptions must derive from BaseException #314

Open jweiher opened 4 months ago

jweiher commented 4 months ago

Hi,

instead of raising a proper Exception(), a string is thrown here https://github.com/fortinet-ansible-dev/ansible-galaxy-fortios-collection/blame/1aeb9fa6dfd24b3c9d9d8b95c29b8a6953854abe/plugins/module_utils/fortios/fortios.py#L108

if len(seg) != 3:
        raise "Invalid fortios system version number: " + version + ". Should be of format [major].[minor].[patch]"

addditionally, in https://github.com/fortinet-ansible-dev/ansible-galaxy-fortios-collection/blob/main/plugins/module_utils/fortios/fortios.py#L114, a BaseException is thrown which is not how Exception handling in python is done. You should not raise BaseException but Exception or (even better) custom subclass of the builtin Exception class:

    if len(one_range) != 2:
        raise BaseException("Incorrect version range, expecting [start, end]: " + str(one_range))

Thank you, Jan

JieX19 commented 4 months ago

Hi @jweiher

Thank you so much for your advice! We'll improve the code you mentioned in the next release.

Thanks, Jie

MaxxLiu22 commented 2 months ago

Hi @jweiher

We just released Ansible FOS 2.3.7. and improved our code according your suggestion, many thanks!

Thanks, Maxx