Boost C++ Libraries: Ticket #3423: Diagnostic of errors. https://svn.boost.org/trac10/ticket/3423 <ol><li>Some classes of errors (for example "unknown_option") are not remembered parameters transferred in the constructor. It does not allow to generate non standard diagnostics (for example not in English). </li><li>In a class "multiple_occurrences" there is no diagnostics for what parameter the error is found out. </li></ol> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3423 Trac 1.4.3 samjmill@… Mon, 09 Nov 2009 18:22:57 GMT cc set https://svn.boost.org/trac10/ticket/3423#comment:1 https://svn.boost.org/trac10/ticket/3423#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">samjmill@…</span> added </li> </ul> <p> added myself </p> Ticket Sascha Ochsenknecht <s.ochsenknecht@…> Wed, 18 Nov 2009 06:55:57 GMT attachment set https://svn.boost.org/trac10/ticket/3423 https://svn.boost.org/trac10/ticket/3423 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">ticket3423.patch</span> </li> </ul> <p> patch </p> Ticket Sascha Ochsenknecht <s.ochsenknecht@…> Wed, 18 Nov 2009 07:00:02 GMT cc changed https://svn.boost.org/trac10/ticket/3423#comment:2 https://svn.boost.org/trac10/ticket/3423#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">s.ochsenknecht@…</span> added </li> </ul> <p> I just attached a patch. </p> <p> It adds the member function get_option_name() to the exceptions: unknown_option, multiple_values, multiple_occurrences and validation_error </p> <p> The option name is set when exception is thrown, this gives the possibility for an appropriate error reporting when catching these exceptions. </p> <p> I also added a new test case program_options/test/exception_test.cpp which checks some exceptions. This test is not fully complete but a good place to add checks related to exceptions. </p> <p> Please comment. </p> Ticket Vladimir Prus Wed, 18 Nov 2009 13:32:52 GMT <link>https://svn.boost.org/trac10/ticket/3423#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3423#comment:3</guid> <description> <p> Sascha, </p> <p> thanks for the patch. It's very nice, and I only found minor formatting things: </p> <ol><li>You seem to add an empty line to the 'error' class definition. I've removed it. </li><li>When you add set_option_name in the cpp file, you leave two empty lines between functions, while the rest of the code uses 1. </li></ol> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Wed, 18 Nov 2009 13:35:17 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3423#comment:4 https://svn.boost.org/trac10/ticket/3423#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/57746" title="Add option name to a few exception classes. Fixes #3423. Patch from ...">[57746]</a>) Add option name to a few exception classes. </p> <p> Fixes <a class="reopened ticket" href="https://svn.boost.org/trac10/ticket/3423" title="#3423: Feature Requests: Diagnostic of errors. (reopened)">#3423</a>. Patch from Sascha Ochsenknecht. </p> Ticket Alex Bukreev <bucreev@…> Tue, 24 Nov 2009 05:55:38 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/3423#comment:5 https://svn.boost.org/trac10/ticket/3423#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> I’ve looked through your changes. There are 12 classes declared in file “errors.hpp”. </p> <ol><li>class “error” – base class, exception in this class are not generated (i suggest to declare its constructor as ‘protected’). </li></ol><ol start="2"><li>class “invalid_syntax” – there is a “msg” parameter of type ‘string’ which is specified in constructor, it is necessary to swap its parameter type to ‘enum’ with storing of its value (like it’s done in class “invalid_command_line_syntax”). </li></ol><ol start="3"><li>class “unknown_option” – ok. </li></ol><ol start="4"><li>class “ambiguous_option” - – there is a “name” parameter specified in constructor. Parameter value must be stored. </li></ol><ol start="5"><li>class "multiple_values" - there is a “what” parameter specified in constructor which is always equal to "multiple_values" parameter. </li></ol><ul><li>remove “what” parameter from constructor. </li></ul><ol start="6"><li>class "multiple_occurrences" - there is a “what” parameter specified in constructor which is always equal to "multiple_values" parameter. </li></ol><ul><li>remove “what” parameter from constructor. </li></ul><ol start="7"><li>class "validation_error - there is a “what” parameter of type ‘string’ specified in constructor. It is necessary to swap its parameter type to ‘enum’ with storing of its value. </li></ol><ol start="8"><li>class "invalid_option_value" - value of parameter "bad_value" is not stored. </li></ol><ol start="9"><li>class "too_many_positional_options_error" – if this exception may occur only because of programmer(not user) mistake, then it’s ok. </li></ol><ol start="10"><li>class "too_few_positional_options_error" - if this exception may occur only because of programmer(not user) mistake, then it’s ok. </li></ol><ol start="11"><li>class "invalid_command_line_syntax" – ok </li></ol><ol start="12"><li>class "invalid_command_line_style" - if this exception may occur only because of programmer(not user) mistake, then it’s ok. </li></ol><p> While testing of “error” classes were detected the following: 1.Source one: </p> <blockquote> <p> options_description desc; desc.add_options() </p> <blockquote> <p> ("cfgfile,c", value&lt;string&gt;()-&gt;multitoken(), "the config file") ("output,c", value&lt;string&gt;(), "the output file") ("output,o", value&lt;string&gt;(), "the output file") </p> </blockquote> <p> ; </p> </blockquote> <p> </p> <blockquote> <p> const char* cmdline[] = {"program", "-c", "file", "-o", "anotherfile"}; </p> </blockquote> <p> No mistake detected!!! </p> <p> 2.Source two: </p> <blockquote> <p> desc.add_options() </p> <blockquote> <p> ("cfgfile,c", value&lt;string&gt;()-&gt;multitoken(), "the config file") ("output,o", value&lt;string&gt;(), "the output file") </p> </blockquote> <p> ; </p> </blockquote> <p> </p> <blockquote> <p> const char* cmdline[] = {"program", "-c", "-o", "anotherfile"}; </p> </blockquote> <p> Wrong diagnostic: "in option 'cfgfile': multiple values not allowed" </p> Ticket Sascha Ochsenknecht Thu, 26 Nov 2009 10:52:00 GMT owner, status, milestone changed https://svn.boost.org/trac10/ticket/3423#comment:6 https://svn.boost.org/trac10/ticket/3423#comment:6 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Vladimir Prus</span> to <span class="trac-author">Sascha Ochsenknecht</span> </li> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">new</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.41.0</span> → <span class="trac-field-new">Boost 1.42.0</span> </li> </ul> Ticket Sascha Ochsenknecht Thu, 26 Nov 2009 10:54:08 GMT status changed https://svn.boost.org/trac10/ticket/3423#comment:7 https://svn.boost.org/trac10/ticket/3423#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Sascha Ochsenknecht Fri, 04 Dec 2009 13:39:23 GMT <link>https://svn.boost.org/trac10/ticket/3423#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3423#comment:8</guid> <description> <p> I hope I cleaned it up a bit. I divided this "workpackage" into two parts to avoid big changes in one commit. So, first part is cleaning up of the exception classes (point 1-12), second part will be debugging the two things Alex detected. </p> <p> First part is done and already on trunk, see my comments below. Second part will come soon, keep the ticket open. </p> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3423#comment:5" title="Comment 5">Alex Bukreev &lt;bucreev@…&gt;</a>: </p> <blockquote class="citation"> <ol><li>class “error” – base class, exception in this class are not generated (i suggest to declare its constructor as ‘protected’). </li></ol></blockquote> <blockquote> <p> -&gt; Currently class error is thrown from several places within the library. </p> <blockquote> <p> I would suggest to introduce a new exception class for them, something like miscellaneous_error and then make constructor protected </p> </blockquote> </blockquote> <p> </p> <blockquote class="citation"> <ol start="2"><li>class “invalid_syntax” – there is a “msg” parameter of type ‘string’ which is specified in constructor, it is necessary to swap its parameter type to ‘enum’ with storing of its value (like it’s done in class “invalid_command_line_syntax”). </li></ol></blockquote> <blockquote> <blockquote> <p> -&gt; DONE. Moved the "kind" to base class invalid_syntax. </p> </blockquote> </blockquote> <blockquote class="citation"> <ol start="3"><li>class “unknown_option” – ok. </li></ol></blockquote> <blockquote class="citation"> <ol start="4"><li>class “ambiguous_option” - – there is a “name” parameter specified in constructor. Parameter value must be stored. </li></ol></blockquote> <blockquote> <p> -&gt; DONE </p> </blockquote> <blockquote class="citation"> <ol start="5"><li>class "multiple_values" - there is a “what” parameter specified in constructor which is always equal to "multiple_values" parameter. </li></ol><ul><li>remove “what” parameter from constructor. </li></ul></blockquote> <blockquote> <p> -&gt; DONE </p> </blockquote> <blockquote class="citation"> <ol start="6"><li>class "multiple_occurrences" - there is a “what” parameter specified in constructor which is always equal to "multiple_values" parameter. </li></ol><ul><li>remove “what” parameter from constructor. </li></ul></blockquote> <blockquote> <p> -&gt; DONE </p> </blockquote> <p> </p> <blockquote class="citation"> <ol start="7"><li>class "validation_error - there is a “what” parameter of type ‘string’ specified in constructor. It is necessary to swap its parameter type to ‘enum’ with storing of its value. </li></ol></blockquote> <blockquote> <p> -&gt; DONE, introduce a kind_t and related function to derive message from </p> <blockquote> <p> kind. </p> </blockquote> </blockquote> <p> </p> <blockquote class="citation"> <ol start="8"><li>class "invalid_option_value" - value of parameter "bad_value" is not stored. </li></ol></blockquote> <blockquote> <p> -&gt; stored now in base class: validation_error </p> </blockquote> <blockquote class="citation"> <ol start="9"><li>class "too_many_positional_options_error" – if this exception may occur only because of programmer(not user) mistake, then it’s ok. </li></ol></blockquote> <blockquote> <blockquote> <p> -&gt; comment added, removed what parameter </p> </blockquote> </blockquote> <blockquote class="citation"> <ol start="10"><li>class "too_few_positional_options_error" - if this exception may occur only because of programmer(not user) mistake, then it’s ok. </li></ol></blockquote> <blockquote> <p> -&gt; class is not used - removed </p> </blockquote> <blockquote class="citation"> <ol start="11"><li>class "invalid_command_line_syntax" – ok </li></ol></blockquote> <blockquote> <blockquote> <p> -&gt; see 2., moved kind_t to base class </p> </blockquote> </blockquote> <p> </p> <blockquote class="citation"> <ol start="12"><li>class "invalid_command_line_style" - if this exception may occur only because of programmer(not user) mistake, then it’s ok. </li></ol></blockquote> <blockquote> <blockquote> <p> -&gt; Comment added </p> </blockquote> </blockquote> <p> In general there are still some TODO's in the code. Storing non-trivial values in exception class might be a bad idea, because their constructors can throw. But I think these things can be kept in for now and marked with a TODO, cleaning up those would be another ticket. </p> <p> With "part-2" I'll also update the test case and add some more checks. </p> <p> Please comment! Reviewing is welcome! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sascha Ochsenknecht</dc:creator> <pubDate>Sat, 05 Dec 2009 08:08:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3423#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3423#comment:9</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3423#comment:5" title="Comment 5">Alex Bukreev &lt;bucreev@…&gt;</a>: </p> <blockquote class="citation"> <p> While testing of “error” classes were detected the following: 1.Source one: </p> <blockquote> <p> options_description desc; desc.add_options() </p> <blockquote> <p> ("cfgfile,c", value&lt;string&gt;()-&gt;multitoken(), "the config file") ("output,c", value&lt;string&gt;(), "the output file") ("output,o", value&lt;string&gt;(), "the output file") </p> </blockquote> <p> ; </p> </blockquote> <p> </p> <blockquote> <p> const char* cmdline[] = {"program", "-c", "file", "-o", "anotherfile"}; </p> </blockquote> </blockquote> <p> Just checkin a solution which throws ambiguous_option exception. This is thrown during parsing of commandline, not during add_options(). </p> <p> Cheers, Sascha </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sascha Ochsenknecht</dc:creator> <pubDate>Sun, 06 Dec 2009 09:52:57 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3423#comment:10 https://svn.boost.org/trac10/ticket/3423#comment:10 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/58184" title="Better detection of missing values on command line, Fixes #3423">[58184]</a>) Better detection of missing values on command line, Fixes <a class="reopened ticket" href="https://svn.boost.org/trac10/ticket/3423" title="#3423: Feature Requests: Diagnostic of errors. (reopened)">#3423</a> </p> Ticket anonymous Sun, 06 Dec 2009 10:00:23 GMT <link>https://svn.boost.org/trac10/ticket/3423#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3423#comment:11</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3423#comment:5" title="Comment 5">Alex Bukreev &lt;bucreev@…&gt;</a>: </p> <blockquote class="citation"> <p> 2.Source two: </p> <blockquote> <p> desc.add_options() </p> <blockquote> <p> ("cfgfile,c", value&lt;string&gt;()-&gt;multitoken(), "the config file") ("output,o", value&lt;string&gt;(), "the output file") </p> </blockquote> <p> ; </p> </blockquote> <p> </p> <blockquote> <p> const char* cmdline[] = {"program", "-c", "-o", "anotherfile"}; </p> </blockquote> <p> Wrong diagnostic: "in option 'cfgfile': multiple values not allowed" </p> </blockquote> <p> It detects "-o" as an option (not a value for "-c"). It now throws invalid_command_line_syntax(invalid_syntax::missing_parameter) for cfgfile. If "-o" should be recognized as value of "-c" it must be quoted. </p> <p> Reviews are welcome :-). If set status to "closed" but if there are still issues feel free to re-open. </p> <p> Thanks, SAscha </p> </description> <category>Ticket</category> </item> <item> <author>stimming@…</author> <pubDate>Tue, 02 Mar 2010 16:45:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3423#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3423#comment:12</guid> <description> <p> Unfortunately in <a class="changeset" href="https://svn.boost.org/trac10/changeset/58138" title="Clean up exception classes, changes regarding to Ticket #3423">[58138]</a> and <a class="changeset" href="https://svn.boost.org/trac10/changeset/58184" title="Better detection of missing values on command line, Fixes #3423">[58184]</a> you changed the previously existing member variable invalid_syntax::tokens into an accessor function invalid_syntax::tokens(). This breaks existing code that wanted to print a helpful error message to the user, and with a rather weird compiler error message. Couldn't you introduce a more graceful change of interface here? Like, at least introducing the accessor function with a different name, so that the developer more easily understands you have removed the public member? Thanks! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vladimir Prus</dc:creator> <pubDate>Sat, 06 Mar 2010 08:46:50 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/3423#comment:13 https://svn.boost.org/trac10/ticket/3423#comment:13 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> Would changing this for 1.43 actually help you, given that 1.42 is already out in the wild with this incompatibility? </p> Ticket stimming@… Sat, 06 Mar 2010 10:10:32 GMT <link>https://svn.boost.org/trac10/ticket/3423#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3423#comment:14</guid> <description> <p> Well, for me it doesn't change anything now that I've encountered this issue and added an #if BOOST_VERSION... workaround. But for other users it would probably be preferrable to solve this differently - maybe add a invalid_syntax::get_tokens() accessor, and marking the invalid_syntax::tokens() accessor as deprecated? </p> <p> It's not an uncommon thing to fix some accidental backward incompatiblity in the next boost version, so yes, it would still be an improvement. </p> </description> <category>Ticket</category> </item> </channel> </rss>