Skip to content

Inproper use of try/except #57

@scibi

Description

@scibi

Hi!

Currently many function bodies are wrapped in something like this:

def do_something(params):
    try:
         #some code
    except Exception as e:
        raise e

This is really bad because you are loosing tracback frames so it gets very hard to debug problems.
For example if you do not provide IPMI address you end with something like this:

2014-12-16 16:06:53,073 - SMGR - DEBUG - reimage_server
2014-12-16 16:06:53,158 - SMGR - DEBUG - *****TRACEBACK-START*****
2014-12-16 16:06:53,159 - SMGR - DEBUG - Traceback (most recent call last):

2014-12-16 16:06:53,159 - SMGR - DEBUG -   File "/opt/contrail/server_manager/server_mgr_main.py", line 2073, in reimage_server
    base_image, package_image_id, reimage_parameters)

2014-12-16 16:06:53,159 - SMGR - DEBUG -   File "/opt/contrail/server_manager/server_mgr_main.py", line 2924, in _do_reimage_server
    raise e

2014-12-16 16:06:53,159 - SMGR - DEBUG - TypeError: cannot marshal None unless allow_none is enabled

2014-12-16 16:06:53,159 - SMGR - DEBUG - *****TRACEBACK-END******

If I remove unnecessary try/except statements (in this case in create_system method of ServerMgrCobbler class) I get:

2014-12-16 16:24:34,888 - SMGR - DEBUG - reimage_server
2014-12-16 16:24:34,907 - SMGR - DEBUG - *****TRACEBACK-START*****
2014-12-16 16:24:34,915 - SMGR - DEBUG - Traceback (most recent call last):

2014-12-16 16:24:34,915 - SMGR - DEBUG -   File "/opt/contrail/server_manager/server_mgr_main.py", line 2073, in reimage_server
    base_image, package_image_id, reimage_parameters)

2014-12-16 16:24:34,915 - SMGR - DEBUG -   File "/opt/contrail/server_manager/server_mgr_main.py", line 2907, in _do_reimage_server
    reimage_parameters.get('partition', ''))

2014-12-16 16:24:34,915 - SMGR - DEBUG -   File "/opt/contrail/server_manager/server_mgr_cobbler.py", line 264, in create_system
    system_id, "power_address", power_address, self._token)

2014-12-16 16:24:34,916 - SMGR - DEBUG -   File "/usr/lib/python2.7/xmlrpclib.py", line 1224, in __call__
    return self.__send(self.__name, args)

2014-12-16 16:24:34,916 - SMGR - DEBUG -   File "/usr/lib/python2.7/xmlrpclib.py", line 1572, in __request
    allow_none=self.__allow_none)

2014-12-16 16:24:34,916 - SMGR - DEBUG -   File "/usr/lib/python2.7/xmlrpclib.py", line 1085, in dumps
    data = m.dumps(params)

2014-12-16 16:24:34,916 - SMGR - DEBUG -   File "/usr/lib/python2.7/xmlrpclib.py", line 632, in dumps
    dump(v, write)

2014-12-16 16:24:34,916 - SMGR - DEBUG -   File "/usr/lib/python2.7/xmlrpclib.py", line 654, in __dump
    f(self, value, write)

2014-12-16 16:24:34,916 - SMGR - DEBUG -   File "/usr/lib/python2.7/xmlrpclib.py", line 658, in dump_nil
    raise TypeError, "cannot marshal None unless allow_none is enabled"

2014-12-16 16:24:34,916 - SMGR - DEBUG - TypeError: cannot marshal None unless allow_none is enabled

2014-12-16 16:24:34,916 - SMGR - DEBUG - *****TRACEBACK-END******

Now it's clear that the there is a problem with power_address.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions