mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +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:
2
changelogs/fragments/11340-cronvar-simplify-exc.yml
Normal file
2
changelogs/fragments/11340-cronvar-simplify-exc.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
minor_changes:
|
||||||
|
- cronvar - simplify handling unknown exceptions (https://github.com/ansible-collections/community.general/pull/11340).
|
||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user