Fix traceback if zonemgr error contains unicode

Ticket: https://fedorahosted.org/freeipa/ticket/4805
Reviewed-By: David Kupka <dkupka@redhat.com>
This commit is contained in:
Martin Basti 2014-12-12 14:23:32 +01:00 committed by Martin Kosek
parent 9225624fd8
commit 727f8099af

View File

@ -411,7 +411,14 @@ def zonemgr_callback(option, opt_str, value, parser):
value = value.decode(encoding)
validate_zonemgr_str(value)
except ValueError, e:
parser.error("invalid zonemgr: " + unicode(e))
# FIXME we can do this in better way
# https://fedorahosted.org/freeipa/ticket/4804
# decode to proper stderr encoding
stderr_encoding = getattr(sys.stderr, 'encoding', None)
if stderr_encoding is None:
stderr_encoding = 'utf-8'
error = unicode(e).encode(stderr_encoding)
parser.error("invalid zonemgr: " + error)
parser.values.zonemgr = value