1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-02-04 07:51:50 +00:00

[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 a0d3bac88c)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2025-12-30 16:20:46 +01:00 committed by GitHub
parent 303bac630a
commit 8d4e702d89
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 3 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- cronvar - simplify handling unknown exceptions (https://github.com/ansible-collections/community.general/pull/11340).

View file

@ -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)