Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.getopt: improve error message for malformed arguments #9662

Open
dlangBugzillaToGithub opened this issue Jun 23, 2015 · 2 comments · May be fixed by #10593
Open

std.getopt: improve error message for malformed arguments #9662

dlangBugzillaToGithub opened this issue Jun 23, 2015 · 2 comments · May be fixed by #10593

Comments

@dlangBugzillaToGithub
Copy link

initrd.gz (@ColonelThirtyTwo) reported this on 2015-06-23T16:33:35Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=14725

CC List

  • rburners

Description

When parsing an argument that isn't a string (ex. an int), getopt just uses `std.conv.to`, which throws a ConvException that's not very helpful to the end user.

For example:


import std.stdio;
import std.getopt;
import std.conv;

void main(string[] args) {
	int num;
	
	GetoptResult helpinfo;
	try {
		helpinfo = getopt(args,
			"num", "An integer", &num,
		);
	} catch(ConvException ex) {
		stderr.writeln("Error parsing arguments: ", ex.msg);
		return;
	}
	
	if(helpinfo.helpWanted) {
		defaultGetoptPrinter("I am help text", helpinfo.options);
	}
}


$ rdmd ~/test.d --num=foo
Error parsing arguments: Unexpected 'o' when converting from type string to type int

It would be nicer if getopt caught the ConvException, then threw a GetOptException with a more end-user-friendly message. For example:

$ rdmd ~/test.d --num=foo
Error parsing arguments: `num` was passed a non-integer value.
@dlangBugzillaToGithub
Copy link
Author

rburners commented on 2015-07-15T09:15:27Z

I will work on that

@dlangBugzillaToGithub
Copy link
Author

rburners commented on 2015-07-15T13:19:35Z

https://github.com/D-Programming-Language/phobos/pull/3491

@thewilsonator thewilsonator removed OS:Linux Issues specific to Linux Arch:x86_64 Issues specific to x86_64 P4 labels Dec 5, 2024
burner added a commit to burner/phobos that referenced this issue Dec 19, 2024
@burner burner linked a pull request Dec 19, 2024 that will close this issue
burner added a commit to burner/phobos that referenced this issue Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants