From 89e0781be777448fc3065a78bad2b7e8ba646532 Mon Sep 17 00:00:00 2001 From: Michael Calmer Date: Tue, 14 Nov 2017 17:02:50 +0100 Subject: [PATCH 1/4] ignore invalid characters when getting decoding error in cmd run --- salt/modules/cmdmod.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/salt/modules/cmdmod.py b/salt/modules/cmdmod.py index 3ae58905c3..f45ae6e84d 100644 --- a/salt/modules/cmdmod.py +++ b/salt/modules/cmdmod.py @@ -589,11 +589,18 @@ def _run(cmd, out = proc.stdout.decode(__salt_system_encoding__) except AttributeError: out = u'' + except UnicodeDecodeError: + log.error("UnicodeDecodeError while decoding output of cmd {0}".format(cmd)) + out = proc.stdout.decode(__salt_system_encoding__, 'ignore') try: err = proc.stderr.decode(__salt_system_encoding__) except AttributeError: err = u'' + except UnicodeDecodeError: + log.error("UnicodeDecodeError while decoding error of cmd {0}".format(cmd)) + err = proc.stderr.decode(__salt_system_encoding__, 'ignore') + if rstrip: if out is not None: From 9b67ec0d3d433eed5ed124a0f50c1f90d357acbc Mon Sep 17 00:00:00 2001 From: Michael Calmer Date: Wed, 29 Nov 2017 16:57:31 +0100 Subject: [PATCH 2/4] use 'replace' strategy for invalid encodings --- salt/modules/cmdmod.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/modules/cmdmod.py b/salt/modules/cmdmod.py index f45ae6e84d..2275204c83 100644 --- a/salt/modules/cmdmod.py +++ b/salt/modules/cmdmod.py @@ -591,7 +591,7 @@ def _run(cmd, out = u'' except UnicodeDecodeError: log.error("UnicodeDecodeError while decoding output of cmd {0}".format(cmd)) - out = proc.stdout.decode(__salt_system_encoding__, 'ignore') + out = proc.stdout.decode(__salt_system_encoding__, 'replace') try: err = proc.stderr.decode(__salt_system_encoding__) @@ -599,7 +599,7 @@ def _run(cmd, err = u'' except UnicodeDecodeError: log.error("UnicodeDecodeError while decoding error of cmd {0}".format(cmd)) - err = proc.stderr.decode(__salt_system_encoding__, 'ignore') + err = proc.stderr.decode(__salt_system_encoding__, 'replace') if rstrip: From bc5f6a1da4d021cf10f64ea3a0adefe0f26ffe7c Mon Sep 17 00:00:00 2001 From: Michael Calmer Date: Thu, 30 Nov 2017 09:24:03 +0100 Subject: [PATCH 3/4] use single quotes --- salt/modules/cmdmod.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/modules/cmdmod.py b/salt/modules/cmdmod.py index 2275204c83..d7193174eb 100644 --- a/salt/modules/cmdmod.py +++ b/salt/modules/cmdmod.py @@ -590,7 +590,7 @@ def _run(cmd, except AttributeError: out = u'' except UnicodeDecodeError: - log.error("UnicodeDecodeError while decoding output of cmd {0}".format(cmd)) + log.error('UnicodeDecodeError while decoding output of cmd {0}'.format(cmd)) out = proc.stdout.decode(__salt_system_encoding__, 'replace') try: @@ -598,7 +598,7 @@ def _run(cmd, except AttributeError: err = u'' except UnicodeDecodeError: - log.error("UnicodeDecodeError while decoding error of cmd {0}".format(cmd)) + log.error('UnicodeDecodeError while decoding error of cmd {0}'.format(cmd)) err = proc.stderr.decode(__salt_system_encoding__, 'replace') From 3be96f7903e10ca695c31e8e1e07c47142a8e270 Mon Sep 17 00:00:00 2001 From: Michael Calmer Date: Thu, 30 Nov 2017 16:48:58 +0100 Subject: [PATCH 4/4] lint fix --- salt/modules/cmdmod.py | 1 - 1 file changed, 1 deletion(-) diff --git a/salt/modules/cmdmod.py b/salt/modules/cmdmod.py index d7193174eb..1b6ce66302 100644 --- a/salt/modules/cmdmod.py +++ b/salt/modules/cmdmod.py @@ -601,7 +601,6 @@ def _run(cmd, log.error('UnicodeDecodeError while decoding error of cmd {0}'.format(cmd)) err = proc.stderr.decode(__salt_system_encoding__, 'replace') - if rstrip: if out is not None: out = out.rstrip()