On 10/14/10 07:48 AM, Jan Damborsky wrote:
On 10/14/10 01:05 PM, [email protected] wrote:
On 10/14/10 03:02 AM, Jan Damborsky wrote:
Hi Keith,

On 10/13/10 06:36 PM, Keith Mitchell wrote:
Hi Jan,

It'd be better to check status and len() of the output before
splitting the output - if the command errors out and returns an empty
string for status, the "co[0].split()[1]" command will fail.

Good point. I went with what Bart suggests, since I think it handles
all kind of potential failures.

If you are interested, I have updated the webrev with those changes:
http://cr.opensolaris.org/~dambi/bug-6991546/

Thank you for review !
Jan

_______________________________________________
caiman-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/caiman-discuss

Hey Jan,

Would it be better to trap on IndexError instead of StandardError?

Hey Joe,

to be honest, I am not sure. I chose StandardError, as it has broader scope
and we want to catch everything.
Looking at the exception hierarchy [1], the related portion looks like

StandardError
+--TypeError
+-- LookupError
+-- IndexError
+-- KeyError

Is IndexError the only exception which could be raised ?
If this is the case, then I agree it is better to go with more specific
IndexError.

Thank you,
Jan


[1] http://docs.python.org/library/exceptions.html


Hey Jan,

A while back Keith had told me the way to determine what exception to trap is to induce the expected error. So I tried this:

boomvangLT > python
Python 2.6.4 (r264:75706, Sep 12 2010, 16:30:49) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
Sourcing ${HOME}/.pythonrc
py 1> co = ''
py 1> x = co[0].split()[1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: string index out of range
py 1>


Since the exception raised is IndexError I thought I would raise the issues.

In looking at the Python documentation regarding exceptions:
http://docs.python.org/tutorial/errors.html

The safest thing may be to have an except IndexError and an unspecified catch all:

2255         try:
2256             preferred_publisher = co[0].split()[1]
2257
2258         except IndexError:
2259 prerror('Could not determine name of preferred publisher from '
2260                     'following input : ' + repr(co))
2261             prerror('Failure. Returning: ICT_PKG_RESET_UUID_FAILED')
2262             return ICT_PKG_RESET_UUID_FAILED

              except:
                 prerror:('Unexpected failure')
                 raise


2263
2264         _dbg_msg('Preferred publisher: ' + preferred_publisher)



Let's see what Keith suggests too.

Joe
_______________________________________________
caiman-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/caiman-discuss

Reply via email to