commit 7ba559afb85d5ecb0ca623259fface870e9e3859 Author: Bryn M. Reeves Date: Sun Oct 6 15:28:27 2013 +0100 Fix exception in command output substitution If an attempt is made to apply command output substitution via Plugin.do_cmd_output_sub() and no output has been collected (i.e. called['file'] == None) an exception is thrown by os.path.join(). The exception is also not logged properly due to an attempt in the do_cmd_output_sub() exception handler to access an unbound local variable (path - the exception occurs before it is assigned). Fix both of these by checking for an empty file entry and avoiding access to the path variable from the exception handler. Signed-off-by: Bryn M. Reeves diff --git a/sos/plugintools.py b/sos/plugintools.py index 4bde7e4..f4f7c0a 100644 --- a/sos/plugintools.py +++ b/sos/plugintools.py @@ -130,6 +130,9 @@ class PluginBase: replacements = 0 try: for called in self.executedCommands: + # was anything collected? + if called['file'] == None: + continue if fnmatch.fnmatch(called['exe'], globstr): path = os.path.join(self.cInfo['cmddir'], called['file']) self.soslog.debug("applying substitution to %s" % path) @@ -144,7 +147,7 @@ class PluginBase: replacements = replacements + replaced except Exception, e: msg = 'regex substitution failed for %s in plugin %s with: "%s"' - self.soslog.error(msg % (path, self.piName, e)) + self.soslog.error(msg % (called['exe'], self.piName, e)) return replacements def doRegexFindAll(self, regex, fname):