chiark / gitweb /
systemd-python: catch only ValueErrors in conversion code
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 Mar 2013 03:15:46 +0000 (22:15 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 Mar 2013 05:45:56 +0000 (00:45 -0500)
commitaaf080611894aa70af421380af3bca23ad998a8d
tree8c5baaf6b9b117ee1a4a3c7f65163c8dff37373d
parent1d98d9a62c16c8282d02942d80e025ceec962c9b
systemd-python: catch only ValueErrors in conversion code

First of all, 'try: ... except: ...' (with no exception specified) is
always a no-no, since it catches all BaseExceptions, which includes ^C
and other stuff which should almost never be caught.

Now the conversion is stricter, and only one conversion is attempted,
and only a ValueEror is caught. It seems reasonable to catch ValueErrors,
since the entries in the journal are not verified, and any erroneous
application might log a field which cannot be converted. The consumer
of events must only check if a field is an instance of bytes and can
otherwise assume that the conversion was performed correctly.

Order of arguments in Reader.__init__ has been changed to match order
in _Reader.__init__.

Conversions have been updated to work under Python 2 and 3.
src/python-systemd/journal.py