On 12/17/12 16:59, Erik Trauschke wrote:


On 12/17/12 02:49 PM, Shawn Walker wrote:
line 1060: s/;//

lol

Can you provide some example output for each case?

You won't see them coming through the client's checking code but I
triggered them artificially and this is how it looks like (after I found
a few more bugs in this piece of code):

incompatible:
InvalidOptionException: The '_new_be' and '_be_name' option may not be
combined
repeated option:
InvalidOptionException: Option '_backup_be' repeated

required option:
InvalidOptionException: '_new_be' may only be used with '_be_name'

xor option:
InvalidOptionException: Either '_backup_be' or '_be_name' must be specified

generic:
InvalidOptionException: invalid option(s): _backup_be _be_name

custom message:
InvalidOptionException: The bobcat is crazy: _backup_be _be_name

(ignore the logical connection between the options, it's just for
showing the message)

We would be able to use these messages in the CLI but the use is very
limited since the testing is very basic and we would just remove a few
lines of checking code and replace it with exception analysis later.
This is more intended for third party clients using the API directly.

I think InvalidOptionException needs to be restructured so that it more naturally handles any number of invalid options. In particular, I'd also expect the __verify_args in pkg.client.api to find as many invalid options as it can before raising the related exception.

Otherwise, this is satisfactory for the moment, although consumers of this will have to manually scan the options that were found to be invalid in the exception and map those to actual options to make it useful for users. With that in mind, maybe there should be a property to map the options to the consumer's representation. For example:

class InvalidOptionException(...):

   option_map = misc.EmptyDict  # Key / Label map for options.
...
  def __str__(self):
     # Move message generation to here; get rid of self.out.
     # Replace option names from "self.options" with text in option_map
     # if an entry is present.
...

# Consumer code.
try:
   api_inst.plan_install(...)
except apx.InvalidOptionException, e:
   e.option_map = my_options
   logger.error(e)
   ...

That would make this a bit more useful and more user-friendly.


-Shawn

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

Reply via email to