From: Daniel Miles Subject: [PATCH] suggested change in exception-handling style of user-space tools Date: Tue, 23 May 2006 10:20:21 -0600 Message-ID: <1148401221.9142.17.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1810803733==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --===============1810803733== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-AE6ZLJ2LO71LLlkwoV51" --=-AE6ZLJ2LO71LLlkwoV51 Content-Type: multipart/mixed; boundary="=-Yv0uT1qTFDLT+Uu/DwHX" --=-Yv0uT1qTFDLT+Uu/DwHX Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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. Singed-off-by: Daniel Miles --=-Yv0uT1qTFDLT+Uu/DwHX Content-Disposition: attachment; filename=exception_handling.patch Content-Type: text/x-patch; name=exception_handling.patch; charset=UTF-8 Content-Transfer-Encoding: base64 ZGlmZiAtciAxM2Q2ZDk5M2Q3OTcgdG9vbHMvcHl0aG9uL3hlbi94bS9jcmVhdGUucHkNCi0tLSBh L3Rvb2xzL3B5dGhvbi94ZW4veG0vY3JlYXRlLnB5CU1vbiBNYXkgMjIgMTY6MzA6MjUgMjAwNg0K KysrIGIvdG9vbHMvcHl0aG9uL3hlbi94bS9jcmVhdGUucHkJVHVlIE1heSAyMyAxMDoxNjo1NCAy MDA2DQpAQCAtOTAzLDEwICs5MDMsMTUgQEANCiAgICAgICAgIGVsc2U6DQogICAgICAgICAgICAg ZXJyKCIlcyIgJSBleC5mYXVsdFN0cmluZykNCiAgICAgZXhjZXB0IEV4Y2VwdGlvbiwgZXg6DQor ICAgICAgICAjIG1haW4ucHkgaGFzIGdvb2QgZXJyb3IgbWVzc2FnZXMgdGhhdCBsZXQgdGhlIHVz ZXIga25vdyB3aGF0IGZhaWxlZC4NCisgICAgICAgICMgdW5sZXNzIHRoZSBlcnJvciBpcyBhIGNy ZWF0ZS5weSBzcGVjaWZpYyB0aGluZywgaXQgc2hvdWxkIGJlIGhhbmRsZWQNCisgICAgICAgICMg YXQgbWFpbi4gVGhlIHB1cnBvc2Ugb2YgdGhpcyBnZW5lcmFsLWNhc2UgJ0V4Y2VwdGlvbicgaGFu ZGxlciBpcyB0bw0KKyAgICAgICAgIyBjbGVhbiB1cCBjcmVhdGUucHkgc3BlY2lmaWMgcHJvY2Vz c2VzL2RhdGEgYnV0IHNpbmNlIGNyZWF0ZS5weSBkb2VzDQorICAgICAgICAjIG5vdCBrbm93IHdo YXQgdG8gZG8gd2l0aCB0aGUgZXJyb3IsIGl0IHNob3VsZCBwYXNzIGl0IHVwLg0KICAgICAgICAg aW1wb3J0IHNpZ25hbA0KICAgICAgICAgaWYgdm5jcGlkOg0KICAgICAgICAgICAgIG9zLmtpbGwo dm5jcGlkLCBzaWduYWwuU0lHS0lMTCkNCi0gICAgICAgIGVycihzdHIoZXgpKQ0KKyAgICAgICAg cmFpc2UgZXgNCiANCiAgICAgZG9tID0gc3hwLmNoaWxkX3ZhbHVlKGRvbWluZm8sICduYW1lJykN CiANCg== --=-Yv0uT1qTFDLT+Uu/DwHX-- --=-AE6ZLJ2LO71LLlkwoV51 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQBEczZFdXmokxhIjnMRAvQBAJ4idaNK0tKel5Buz0LIOgUFHq3llACeMa8q zyBr6oGOJtPd1kjvoQLhNyQ= =nQP4 -----END PGP SIGNATURE----- --=-AE6ZLJ2LO71LLlkwoV51-- --===============1810803733== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============1810803733==--