Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inproper use of try/except #57

Open
scibi opened this issue Dec 16, 2014 · 0 comments
Open

Inproper use of try/except #57

scibi opened this issue Dec 16, 2014 · 0 comments

Comments

@scibi
Copy link

scibi commented Dec 16, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant