From 8d4e702d895534d364bc99669672a420ddd6bdb4 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 30 Dec 2025 16:20:46 +0100 Subject: [PATCH] [PR #11340/a0d3bac8 backport][stable-12] cronvar: simplify exception raise - remove import sys (#11348) cronvar: simplify exception raise - remove import sys (#11340) * cronvar: simplify exception raise - remove import sys * add changelog frag (cherry picked from commit a0d3bac88cb84253bcb25f4ff1f7c6e2fb629eb2) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --- changelogs/fragments/11340-cronvar-simplify-exc.yml | 2 ++ plugins/modules/cronvar.py | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/11340-cronvar-simplify-exc.yml diff --git a/changelogs/fragments/11340-cronvar-simplify-exc.yml b/changelogs/fragments/11340-cronvar-simplify-exc.yml new file mode 100644 index 0000000000..e50cbd39bd --- /dev/null +++ b/changelogs/fragments/11340-cronvar-simplify-exc.yml @@ -0,0 +1,2 @@ +minor_changes: + - cronvar - simplify handling unknown exceptions (https://github.com/ansible-collections/community.general/pull/11340). diff --git a/plugins/modules/cronvar.py b/plugins/modules/cronvar.py index 147891e58e..01dfe0b8b8 100644 --- a/plugins/modules/cronvar.py +++ b/plugins/modules/cronvar.py @@ -101,7 +101,6 @@ import platform import pwd import re import shlex -import sys import tempfile from shlex import quote as shlex_quote @@ -162,7 +161,7 @@ class CronVar: # cron file does not exist return except Exception as e: - raise CronVarError("Unexpected error:", sys.exc_info()[0]) from e + raise CronVarError(f"Unexpected error: {e}", type(e)) from e else: # using safely quoted shell for now, but this really should be two non-shell calls instead. FIXME (rc, out, err) = self.module.run_command(self._read_user_execute(), use_unsafe_shell=True) @@ -219,7 +218,7 @@ class CronVar: # cron file does not exist return False except Exception as e: - raise CronVarError("Unexpected error:", sys.exc_info()[0]) from e + raise CronVarError(f"Unexpected error: {e}", type(e)) from e def parse_for_var(self, line): lexer = shlex.shlex(line)