mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-22 13:19:13 +00:00
* ModuleHelper: ensure compatibility with `ModuleTestCase`. This change allows to configure the `module_fails_on_exception` decorator by passing a tuple of exception types that should not be handled by the decorator itself. In the context of `ModuleTestCase`, use `(AnsibleExitJson, AnsibleFailJson)` to let them pass through the decorator without modification. Signed-off-by: Fiehe Christoph <c.fiehe@eurodata.de> * Another approach allowing user-defined exception types to pass through the decorator. When the decorator should have no arguments at all, we must hard code the name of the attribute that is looked up on self. Signed-off-by: Fiehe Christoph <c.fiehe@eurodata.de> * Approach that removes decorator parametrization and relies on an object/class variable named `unhandled_exceptions`. Signed-off-by: Fiehe Christoph <c.fiehe@eurodata.de> * context manager implemented that allows to pass through some exception types Signed-off-by: Fiehe Christoph <c.fiehe@eurodata.de> * Update changelogs/fragments/11488-mh-ensure-compatibiliy-with-module-tests.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Exception placeholder added Signed-off-by: Fiehe Christoph <c.fiehe@eurodata.de> --------- Signed-off-by: Fiehe Christoph <c.fiehe@eurodata.de> Co-authored-by: Fiehe Christoph <c.fiehe@eurodata.de> Co-authored-by: Felix Fontein <felix@fontein.de>
21 lines
712 B
Python
21 lines
712 B
Python
# (c) 2020, Alexei Znamensky <russoz@gmail.com>
|
|
# Copyright (c) 2020, Ansible Project
|
|
# Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
|
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
from __future__ import annotations
|
|
|
|
import typing as t
|
|
|
|
|
|
class ModuleHelperException(Exception):
|
|
def __init__(self, msg: str, update_output: dict[str, t.Any] | None = None, *args, **kwargs) -> None:
|
|
self.msg: str = msg or f"Module failed with exception: {self}"
|
|
if update_output is None:
|
|
update_output = {}
|
|
self.update_output: dict[str, t.Any] = update_output
|
|
super().__init__(*args)
|
|
|
|
|
|
class _UnhandledSentinel(Exception):
|
|
pass
|