move exception_to_str behavior to common place

Bug #1419588 reported by Kun Huang on 2015-02-09
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance
Wishlist
Unassigned

Bug Description

The function exception_to_str() has a history https://review.openstack.org/#/c/37421/ and it makes:

LOG.warn('The bug is %s: ' % e)

to

LOG.warn(The bug is %s: ' % exception_to_str(e))

It's not so concise, because the log message writer would care about python encoding issues when they writing something. We could move the behavior of using this function to GlanceException.__init__, and more codes could keep better readability. And the best benefit in mind is that once we change original ideas https://review.openstack.org/#/c/37421/ someday, we could only fix a small amount of codes.

Erno Kuvaja (jokke) on 2015-02-10
Changed in glance:
importance: Undecided → Wishlist
Ian Cordasco (icordasc) wrote :

This isn't used in GlanceException though so it doesn't make sense to move it there. Could you expand on how this would be worthwhile in GlanceException.__init__?

Changed in glance:
status: New → Incomplete
Kun Huang (academicgareth) wrote :

@Ian

Seeing the history, the logging module doesn't encode/decode strings very well. So we have to encode/decode before the log behavior. Putting this in common place could make codes clean.

But I found __init__ is not the good choice. __str__/__unicode__ is better in this case, because:

LOG(err) calls err.__str__ and would fail in some character. So the duty to pass correct encoded or decoded string is the duty of __str__/__unicode__.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers