MCPcopy
hub / github.com/saltstack/salt / raise_exception

Function raise_exception

salt/modules/test.py:643–683  ·  view source on GitHub ↗

Raise an exception. Built-in exceptions and those in :mod:`salt.exceptions ` can be raised by this test function. If no matching exception is found, then no exception will be raised and this function will return ``False``. This function is design

(name, *args, **kwargs)

Source from the content-addressed store, hash-verified

641
642
643def raise_exception(name, *args, **kwargs):
644 """
645 Raise an exception. Built-in exceptions and those in
646 :mod:`salt.exceptions <salt.internals.salt.exceptions>`
647 can be raised by this test function. If no matching exception is found,
648 then no exception will be raised and this function will return ``False``.
649
650 This function is designed to test Salt&#x27;s exception and return code
651 handling.
652
653 CLI Example:
654
655 .. code-block:: bash
656
657 salt '*' test.raise_exception TypeError "An integer is required"
658 salt '*' test.raise_exception salt.exceptions.CommandExecutionError "Something went wrong"
659 """
660
661 def _is_exc(cls):
662 for base in cls.__bases__:
663 if base is BaseException:
664 break
665 else:
666 return _is_exc(base)
667 else:
668 return False
669 return True
670
671 try:
672 if name.startswith("salt.exceptions."):
673 exc = getattr(salt.exceptions, name[16:])
674 else:
675 exc = getattr(builtins, name)
676 if _is_exc(exc):
677 raise exc(*args, **salt.utils.args.clean_kwargs(**kwargs))
678 else:
679 log.error("%s is not an exception", name)
680 return False
681 except AttributeError:
682 log.error("No such exception: %s", name)
683 return False
684
685
686def deprecation_warning():

Callers

nothing calls this directly

Calls 2

_is_excFunction · 0.85
errorMethod · 0.45

Tested by

no test coverage detected