gonchik / munki

Automatically exported from code.google.com/p/munki
Other
0 stars 0 forks source link

Unicode encoding errors - in report code - exception #55

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Generate an error that is handled by munkicommon.display_error and contains a 
unicode character.

Unhandled exception results.

Jan 13 12:20:25 Preparing for installation…
Jan 13 12:20:25  The upgrade failed (The Installer can’t locate the data it 
needs to install the software. Check your install m
Jan 13 12:20:29 Install of Remote Desktop Admin Update failed.
Jan 13 12:20:29 ERROR: 
------------------------------------------------------------------------------
Jan 13 12:20:29 ERROR: installer: Package name is Remote Desktop Admin Update
Jan 13 12:20:29 ERROR: installer: Upgrading at base path /
Jan 13 12:20:29 ERROR: installer:PHASE:Preparing for installation…
Jan 13 12:20:29 ERROR: Unexpected error in  installAppleUpdates:
Jan 13 12:20:29 ERROR: Traceback (most recent call last):
  File "/usr/local/munki/managedsoftwareupdate", line 180, in doInstallTasks
    need_to_restart = appleupdates.installAppleUpdates()
  File "/usr/local/munki/munkilib/appleupdates.py", line 519, in installAppleUpdates
    appleupdatelist)
  File "/usr/local/munki/munkilib/installer.py", line 599, in installWithInfo
    suppressBundleRelocation)
  File "/usr/local/munki/munkilib/installer.py", line 230, in installall
    suppressBundleRelocation)
  File "/usr/local/munki/munkilib/installer.py", line 179, in install
    munkicommon.display_error(line.rstrip("\n"))
  File "/usr/local/munki/munkilib/munkicommon.py", line 293, in display_error
    report['Errors'].append(str(msg))
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026' in position 
42: ordinal not in range(128)

Perhaps 'str(  )' is unsafe in general; would simply using 'unicode(  )' to 
ensure we have a string object rather than some other object work in most 
places?

Original issue reported on code.google.com by rrmiddleton@gmail.com on 13 Jan 2011 at 1:43

GoogleCodeExporter commented 8 years ago
In code I have not yet checked in I dealt with the issue like so:

report['Errors'].append('%s' % msg)

Which seems to work with just about any Python object. I don't know if that's 
an accepted Python idiom, though...

Original comment by gregnea...@mac.com on 13 Jan 2011 at 3:20

GoogleCodeExporter commented 8 years ago
'%s' % msg
looks good to me:
http://docs.python.org/library/stdtypes.html#string-formatting

Perhaps even better:
u'%s' % msg
that should ensure that it is always unicode. Otherwise it will sometimes 
return an ascii 'str' object and sometimes a 'unicode' object (depending on 
whether msg is string or unicode or object).

Original comment by rrmiddleton@gmail.com on 13 Jan 2011 at 4:08

GoogleCodeExporter commented 8 years ago
Hmm - on second thoughts:
'%s' % msg
could still complain if msg is an object the is a tuple.

Whereas str(msg) or unicode(msg) should convert a tuple to a string 
representation too.

That is you should be able to throw any object at unicode(msg) and not get an 
exception.

Original comment by rrmiddleton@gmail.com on 13 Jan 2011 at 4:10

GoogleCodeExporter commented 8 years ago
Greg fixed this specific instance in r995. Any greater rework of unicode & 
subprocess handling not until post 0.7.

Original comment by rrmiddleton@gmail.com on 1 Mar 2011 at 11:01