suggested change in exception-handling style of user-space tools
PATCH 1/1 suggested change in exception-handling style of user-space tools
In the tools/python/xen/xm directory, main.py has good error messages that let the user know what failed; the other 'sub-command' classes don't always have such good messages which can lead to some inexplicable failures by the user-space tools.
Standard practice is to except each error by type and react accordingly but in case the programmer does not anticipate a type of exception, standard practice is to put in a catch-all exception handler that excepts an 'Exception' object. Often in this case, the system will print out the exception and exit.
If a sub-command excepts an 'Exception' object and the error is not specific to that sub-command, it should pass the exception up for main to handle. Especially in light of the fact that there is already a broad collection of good error messages in main, I believe that this will lead to better code re-use in the form of a one-stop-shop for error messages. In this patch I've changed only one of the general case exception handlers in one of the sub-commands (xm create) as a test-balloon to see if the xen community will accept future patches of this type.
tools/python/xen/xm/create.py +6 -1
@@ -903,10 +903,15 @@ else: err("%s" % ex.faultString) except Exception, ex: + # main.py has good error messages that let the user know what failed. + # unless the error is a create.py specific thing, it should be handled + # at main. The purpose of this general-case 'Exception' handler is to + # clean up create.py specific processes/data but since create.py does + # not know what to do with the error, it should pass it up. import signal if vncpid: os.kill(vncpid, signal.SIGKILL) - err(str(ex)) + raise ex dom = sxp.child_value(dominfo, 'name')
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Ewan Mellor
AppliedQuoted 11 lines · Daniel Miles
In the
tools/python/xen/xmdirectory,main.pyhas good error messages that let the user know what failed; the other 'sub-command' classes don't always have such good messages which can lead to some inexplicable failures by the user-space tools.Standard practice is to except each error by type and react accordingly but in case the programmer does not anticipate a type of exception, standard practice is to put in a catch-all exception handler that excepts an 'Exception' object. Often in this case, the system will print out the exception and exit.
Quoted 8 lines
If a sub-command excepts an 'Exception' object and the error is not specific to that sub-command, it should pass the exception up for main to handle. Especially in light of the fact that there is already a broad collection of good error messages in main, I believe that this will lead to better code re-use in the form of a one-stop-shop for error messages. In this patch I've changed only one of the general case exception handlers in one of the sub-commands (xm create) as a test-balloon to see if the xen community will accept future patches of this type.
Applied, thank you. Patches for cleaning up the error handling and diagnosis are always welcome, so feel free to send more!
Quoted 1 line
Singed-off-by Daniel Miles <[email protected]>
I like the idea of a patch, gently burned around the edges ;-)
Ewan.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel