Skip to content

Commit 604b4ce

Browse files
IgorFedchenkoAaronontheweb
authored andcommitted
Improve exception text when failed to parse TimeSpan value (#145)
1 parent 48888a2 commit 604b4ce

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Hocon/Impl/HoconValue.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,13 @@ public TimeSpan GetTimeSpan(bool allowInfinite = true)
571571

572572
private static double ParsePositiveValue(string v)
573573
{
574-
var value = double.Parse(v, NumberFormatInfo.InvariantInfo);
574+
// This NumberStyles are used in double.TryParse(v, out var value) overload internally
575+
if (!double.TryParse(v, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.InvariantInfo, out var value))
576+
throw new FormatException($"Failed to parse TimeSpan value from '{v}'");
577+
575578
if (value < 0)
576579
throw new FormatException("Expected a positive value instead of " + value);
580+
577581
return value;
578582
}
579583

0 commit comments

Comments
 (0)