D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2958 - std.getopt RangeError on missing arg
Summary: std.getopt RangeError on missing arg
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: Andrei Alexandrescu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-10 01:19 UTC by Unknown W. Brackets
Modified: 2015-06-09 01:27 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Unknown W. Brackets 2009-05-10 01:19:50 UTC
Currently, using std.getopt will result in a RangeError if parameters are improperly omitted on the command line.  Since this is a reasonable user-error, it does not seem like something to crash on during release.

The problem is here:

            if (!isDelegateWithLessThanTwoParameters && !val && !incremental) {
                // eat the next argument too
                val = args[i];
                args = args[0 .. i] ~ args[i + 1 .. $];
            }

It just needs a check to see if args.length is high enough for this to happen.  And the documentation should note the exception it throws; currently it says only a ConvError is thrown.

-[Unknown]
Comment 1 David Simcha 2010-08-20 17:20:16 UTC
http://dsource.org/projects/phobos/changeset/1905