aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Moravec <pmoravec@redhat.com>2018-09-08 17:39:32 +0200
committerBryn M. Reeves <bmr@redhat.com>2018-12-14 11:18:29 +0000
commit18ae45219c9aa5ed2340a21e9f0aacad62d69242 (patch)
treeb8945fd3b8dc861588ffaca8c8b38086bafa74c0
parent9135d767e6244d370d8cbd59a75e1a56b928d4a3 (diff)
downloadsos-18ae45219c9aa5ed2340a21e9f0aacad62d69242.tar.gz
[plugins] fix exception when collecting empty strings
get first line of string to log only for nonempty content Relevant to: #1422 Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
-rw-r--r--sos/plugins/__init__.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index c87ae19b..6c3b153e 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -746,9 +746,10 @@ class Plugin(object):
def add_string_as_file(self, content, filename):
"""Add a string to the archive as a file named `filename`"""
self.copy_strings.append((content, filename))
- content = content.splitlines()[0]
- if not isinstance(content, six.string_types):
- content = content.decode('utf8', 'ignore')
+ if content:
+ content = content.splitlines()[0]
+ if not isinstance(content, six.string_types):
+ content = content.decode('utf8', 'ignore')
self._log_debug("added string ...'%s' as '%s'" % (content, filename))
def get_cmd_output_now(self, exe, suggest_filename=None,
@@ -948,9 +949,11 @@ class Plugin(object):
def _collect_strings(self):
for string, file_name in self.copy_strings:
- content = string.splitlines()[0]
- if not isinstance(content, six.string_types):
- content = content.decode('utf8', 'ignore')
+ content = ''
+ if string:
+ content = string.splitlines()[0]
+ if not isinstance(content, six.string_types):
+ content = content.decode('utf8', 'ignore')
self._log_info("collecting string ...'%s' as '%s'"
% (content, file_name))
try: