diff options
author | Dirk Mueller <dirk@dmllr.de> | 2015-02-13 15:34:47 +0100 |
---|---|---|
committer | Roman Bogorodskiy <bogorodskiy@gmail.com> | 2015-09-09 21:07:02 +0200 |
commit | 3e7f80608025166c35bcf97c630c0578e798b796 (patch) | |
tree | 947b619873f7a4be92633afaf7e235a2ee455cb6 /keystoneclient/common | |
parent | 28138b588224c6b0503620ac2e24bd37dad25370 (diff) | |
download | python-keystoneclient-3e7f80608025166c35bcf97c630c0578e798b796.tar.gz |
Avoid message concatenation in error path
Recently, the error message in _process_communicate_handle_oserror()
has been i18n'ed, which caused the regression as another code path
appended a string to it, which causes the TypeError to be raised.
Fix it by using string formatting instead of '+' to force it
to convert to string before concatenating.
Closes-Bug: 1421652
Change-Id: I7229b46888f798ac4a69c140ab389afed49b8c3c
Diffstat (limited to 'keystoneclient/common')
-rw-r--r-- | keystoneclient/common/cms.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/keystoneclient/common/cms.py b/keystoneclient/common/cms.py index 1bd0f41..21cd394 100644 --- a/keystoneclient/common/cms.py +++ b/keystoneclient/common/cms.py @@ -85,9 +85,7 @@ def _check_files_accessible(files): except IOError as e: # Catching IOError means there is an issue with # the given file. - err = _('Hit OSError in _process_communicate_handle_oserror()\n' - 'Likely due to %(file)s: %(error)s') % {'file': try_file, - 'error': e.strerror} + err = try_file, e.strerror # Emulate openssl behavior, which returns with code 2 when # access to a file failed. retcode = OpensslCmsExitStatus.INPUT_FILE_READ_ERROR @@ -111,12 +109,25 @@ def _process_communicate_handle_oserror(process, data, files): retcode, err = _check_files_accessible(files) if process.stderr: msg = process.stderr.read() - err = err + msg.decode('utf-8') + if isinstance(msg, six.binary_type): + msg = msg.decode('utf-8') + if err: + err = (_('Hit OSError in ' + '_process_communicate_handle_oserror(): ' + '%(stderr)s\nLikely due to %(file)s: %(error)s') % + {'stderr': msg, + 'file': err[0], + 'error': err[1]}) + else: + err = (_('Hit OSError in ' + '_process_communicate_handle_oserror(): %s') % msg) + output = '' else: retcode = process.poll() if err is not None: - err = err.decode('utf-8') + if isinstance(err, six.binary_type): + err = err.decode('utf-8') return output, err, retcode |