Some classes derived from SavannaException do not overload the "message" and "code" members correctly

Bug #1221302 reported by Trevor McKay
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Sahara
Triaged
Medium
Unassigned

Bug Description

There are some classes derived from SavannaException that do not override message and code members correctly, so that when they are raised the exception message is incorrect. This can result for instance in validation error messages through the REST api that say "An unknown exception occurred" instead of the correct error.

The code should be searched for all derivations from SavannaException, and the declarations and __init_ methods checked.

The SavannException class is declared like this:

class SavannaException(ex.ApiError):
    """Base Exception for the project

    To correctly use this class, inherit from it and define
    a 'message' and 'code' properties.
    """
    message = "An unknown exception occurred"
    code = "UNKNOWN_EXCEPTION"

    def __str__(self):
        return self.message

Derived classes need to set message and code either by overriding the values outside of the __init__ method or by referencing them as self.message and self.code. This is a correct example:

class InvalidException(SavannaException):
    message = "Invalid object reference"

    def __init__(self, message=None):
        self.code = "INVALID_REFERENCE"
        if message:
            self.message = message

Here is an incorrect example. The message and code members inside the __init__ are local to the method, they should be referenced as self.message and self.code or the assignments should be moved outside of __init__:

class HiveWithoutJobTracker(e.SavannaException):
    def __init__(self):
        message = "Hive cannot be configured without JobTracker"
        code = "HIVE_WITHOUT_JOB_TRACKER"

        super(HiveWithoutJobTracker, self).__init__(message, code)

ruhe (ruhe)
Changed in savanna:
status: New → Triaged
importance: Undecided → Medium
milestone: none → 0.3a1
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.