From 8ef27fa80589fcda452fc1c27c1fc6a0fb385b4a Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Thu, 21 Jan 2016 13:06:56 +0530 Subject: [sosreport] Added error handling in Config Parsing Closes: #739. Signed-off-by: Abhijeet Kasurde --- sos/sosreport.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sos/sosreport.py b/sos/sosreport.py index f61ea4a4..f2f30ae8 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -49,9 +49,9 @@ from six.moves import zip, input from six import print_ if six.PY3: - from configparser import ConfigParser + from configparser import ConfigParser, ParsingError, Error else: - from ConfigParser import ConfigParser + from ConfigParser import ConfigParser, ParsingError, Error # file system errors that should terminate a run fatal_fs_errors = (errno.ENOSPC, errno.EROFS) @@ -817,10 +817,17 @@ class SoSReport(object): config_file = self.opts.config_file else: config_file = '/etc/sos.conf' + try: - self.config.readfp(open(config_file)) - except IOError: - pass + try: + with open(config_file) as f: + self.config.readfp(f) + except (ParsingError, Error) as e: + raise exit('Failed to parse configuration ' + 'file %s' % config_file) + except (OSError, IOError) as e: + raise exit('Unable to read configuration file %s ' + ': %s' % (config_file, e.args[1])) def _setup_logging(self): # main soslog -- cgit