Skip to content

Commit

Permalink
Cleanup the error message with nullable types when invalid values are…
Browse files Browse the repository at this point in the history
… used.

"Could not convert string `' to type Nullable`1..." is not nearly as helpful as
"Could not convert string `' to type Int32...".

	* src/NDesk.Options/NDesk.Options/Options.cs: Use the underlying
	  target type in the error message.
	* src/NDesk.Options/Test/NDesk.Options/OptionSetTest.cs: Add a test
	  for the underlying target type within the exception message.
  • Loading branch information
jonpryor committed Oct 23, 2008
1 parent 564b2bd commit 1e9bb6d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/NDesk.Options/NDesk.Options/Options.cs
Expand Up @@ -360,7 +360,7 @@ protected static T Parse<T> (string value, OptionContext c)
throw new OptionException (
string.Format (
c.OptionSet.MessageLocalizer ("Could not convert string `{0}' to type {1} for option `{2}'."),
value, typeof (T).Name, c.OptionName),
value, targetType.Name, c.OptionName),
c.OptionName, e);
}
return t;
Expand Down
3 changes: 3 additions & 0 deletions src/NDesk.Options/Test/NDesk.Options/OptionSetTest.cs
Expand Up @@ -169,6 +169,9 @@ public void OptionalValues ()
Assert.AreEqual (n.Value, 42);
p.Parse (_("-n"));
Assert.AreEqual (n.HasValue, false);
Utils.AssertException (typeof(OptionException),
"Could not convert string `' to type Int32 for option `-n'.",
p, v => { v.Parse (_("-n=")); });
}

[Test]
Expand Down

0 comments on commit 1e9bb6d

Please sign in to comment.