Boost logo

Boost :

Subject: [boost] [program_options] error reporting from custom validators
From: Monty Taylor (mordred_at_[hidden])
Date: 2010-06-27 18:50:24


I've been working on using notifier() to register a custom validator for
an option. If the validator doesn't pass, it throws
invalid_option_value. The issue I'm running in to though is that I do
not have an context to report which option had a problem- I'm actually
also really just abusing the notifier system as well, as I throw
invalid_option_value with a descriptive message instead of just the
option value.

If I pass in an already bogus value, such as passing in a string to an
int option, I get something like this:

Error processing options: in option 'connect_timeout': invalid option
value 'eggs'

So it seems there are places where the code is validating options
(seemingly just from any_cast) with context of which option is being

Is there some place I'm missing to hook a validator in where throwing an
exception would properly pick up option name context? I saw this comment:

                /* We call validate so that if user provided
                   a validator for class T, we use it even
                   when parsing vector<T>. */

What I'd really love would be if I could call something like
validator(some_validator).validator(some_other_validator), and that
those would be passed some sort of context.

Specifically, in the code we're working on replacing, it's quite easy to
specify a min and max value for an integer option, and I'm trying to
figure out a good way to keep this without requiring folks to write a
completely independent notifier function for each option that emits its
own error message.

Any thoughts on where I might want to go with this?

Boost list run by bdawes at, gregod at, cpdaniel at, john at