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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

jweiher opened this issue · comments

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

Hi @jweiher

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

Thanks,
Jie