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

cronvar: simplify exception raise - remove import sys (#11340)

* cronvar: simplify exception raise - remove import sys

* add changelog frag
This commit is contained in:
Alexei Znamensky 2025-12-31 04:09:24 +13:00 committed by GitHub
parent 266d9d3fb0
commit a0d3bac88c
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 pwd
import re import re
import shlex import shlex
import sys
import tempfile import tempfile
from shlex import quote as shlex_quote from shlex import quote as shlex_quote
@ -162,7 +161,7 @@ class CronVar:
# cron file does not exist # cron file does not exist
return return
except Exception as e: 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: else:
# using safely quoted shell for now, but this really should be two non-shell calls instead. FIXME # 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) (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 # cron file does not exist
return False return False
except Exception as e: 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): def parse_for_var(self, line):
lexer = shlex.shlex(line) lexer = shlex.shlex(line)