From 9bbf6efe28c35c94e4ed2a049e02acf3e2cdfd8e Mon Sep 17 00:00:00 2001 From: Mariam Ahhttouche Date: Mon, 16 Feb 2026 11:42:49 +0100 Subject: [PATCH] uv_python module: improve exception handling --- plugins/modules/uv_python.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/modules/uv_python.py b/plugins/modules/uv_python.py index 88609c2c07..9b5bcd9a81 100644 --- a/plugins/modules/uv_python.py +++ b/plugins/modules/uv_python.py @@ -146,17 +146,19 @@ def main(): msg="", ) state = module.params["state"] - uv = UV(module) - if state == "present": - result["changed"], result["msg"] = uv.install_python() - elif state == "absent": - result["changed"], result["msg"] = uv.uninstall_python() - elif state == "latest": - result["changed"], result["msg"] = uv.upgrade_python() - - module.exit_json(**result) + try: + uv = UV(module) + if state == "present": + result["changed"], result["msg"] = uv.install_python() + elif state == "absent": + result["changed"], result["msg"] = uv.uninstall_python() + elif state == "latest": + result["changed"], result["msg"] = uv.upgrade_python() + module.exit_json(**result) + except Exception as e: + module.fail_json(msg=str(e)) if __name__ == "__main__": main() \ No newline at end of file