Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jweiher opened this issue May 28, 2024 · 2 comments

Comments

@jweiher
Copy link

jweiher commented May 28, 2024

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
Copy link

JieX19 commented Jun 3, 2024

Hi @jweiher

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

Thanks,
Jie

@MaxxLiu22
Copy link

Hi @jweiher

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

Thanks,
Maxx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants