DRY queuest.storage.errors

Bug #1260392 reported by Kurt Griffiths on 2013-12-12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cindy Pallares

Bug Description

I think we could reduce lines of code by having a base exception class that takes a **kwargs param, and uses that to format the message like so:

class ExceptionBase(Exception):
    def __init__(self, **kwargs):
        msg = self.msg_format.format(**kwargs)
        super(ExceptionBase, self).__init__(msg)

class QueueIsEmpty(ExceptionBase):

    msg_format = u'Queue {name} in project {project} is empty'

    def __init__(self, name, project):
        super(QueueIsEmpty, self).__init__(name=name, project=project)

Flavio Percoco (flaper87) wrote :

We don't need to override `__init__`. We could pass `kwargs` during the instantiation of the exception. I've seen this in other projects as well.

Changed in marconi:
status: New → Triaged
importance: Undecided → Low
tags: added: low-hanging-fruit
Changed in marconi:
milestone: none → icehouse-2
importance: Low → Wishlist
Changed in marconi:
assignee: nobody → Cindy Pallares (cindy-pallaresq)
Kurt Griffiths (kgriffs) wrote :

I kind of like overriding init because it makes it more obvious what args are expected...

Fix proposed to branch: master
Review: https://review.openstack.org/62701

Changed in marconi:
status: Triaged → In Progress

Reviewed: https://review.openstack.org/62701
Committed: https://git.openstack.org/cgit/openstack/marconi/commit/?id=2073b959bd845b18483869f43721003d9601e0e0
Submitter: Jenkins
Branch: master

commit 2073b959bd845b18483869f43721003d9601e0e0
Author: cpallares <email address hidden>
Date: Tue Dec 17 10:15:03 2013 -0600

    DRY queues storage error message format

    This reduces the lines of codes by having all the errors inherit
    from a base class. This base class takes keyword arguments and
    formats all the error messages uniformly.

    Closes-Bug: #1260392

    Change-Id: I77fcd14e9fb8989c29e0796d813ef587a26f9199

Changed in marconi:
status: In Progress → Fix Committed
Thierry Carrez (ttx) on 2014-01-22
Changed in marconi:
status: Fix Committed → Fix Released
Thierry Carrez (ttx) on 2014-04-17
Changed in marconi:
milestone: icehouse-2 → 2014.1
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers