-
Notifications
You must be signed in to change notification settings - Fork 388
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
🚸Describe why Parse fails due to case-insensitive ambiguity #1484
Conversation
Fixes #1423 `UnitParser.Parse<LengthUnit>("MM")` fails due to matching both `Megameter` and `Millimeter` in case-insensitive matching, but matches neither of them in the case-sensitive fallback. It was confusing to get `UnitsNotFoundException` in this case, since case-insensitive usually works for most untis. ### Changes - Handle this case and throw `AmbiguousUnitParseException` instead of `UnitNotFoundException` - Describe the case-insensitive units that matched
@lipchev relevant to your exception helpers PR, the exception message can be improved further to include information about the quantity and unit enum type, which I believe you already did there. |
Yes, I was also going to bring this is up (eventually) - if we want to go wild we could even include extra fields like in these examples: throw new UnitNotFoundException($"No unit was found for quantity '{quantityName}' with the name: '{unitName}'.")
{
Data = { ["quantityName"] = quantityName, ["unitName"] = unitName }
}; throw new UnitNotFoundException($"No quantity was found with the specified unit type: '{unitType}'.") { Data = { ["unitType"] = unitType.Name } }; |
…rowsUnitNotFoundException
Fixed test case that broken in CI, due to different current culture: def3211 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1484 +/- ##
======================================
Coverage 84% 84%
======================================
Files 368 368
Lines 35601 35606 +5
======================================
+ Hits 30000 30005 +5
Misses 5601 5601 ☔ View full report in Codecov by Sentry. |
@lipchev Are you still reviewing this or can I merge? |
Well, my earlier comment wasn't about the test that broke the build - it was a bit more subtle than that.. |
Gotcha, I'll merge this then. |
…en#1484) Fixes angularsen#1423 `UnitParser.Parse<LengthUnit>("MM")` fails due to matching both `Megameter` and `Millimeter` in case-insensitive matching, but matches neither of them in the case-sensitive fallback. It was confusing to get `UnitsNotFoundException` in this case, since case-insensitive usually works for most units. ### Changes - Handle this case and throw `AmbiguousUnitParseException` instead of `UnitNotFoundException` - Describe the case-insensitive units that matched - Fix existing test `Parse_WithMultipleCaseInsensitiveMatchesButNoExactMatches_ThrowsUnitNotFoundException` - Skip retrying with fallback culture if no specific `formatProvider` was given
… UnitNotFoundException (#1484) (#1494) Fixes #1423 for `release-v6` Carry over from #1484 `UnitParser.Parse<LengthUnit>("MM")` fails due to matching both `Megameter` and `Millimeter` in case-insensitive matching, but matches neither of them in the case-sensitive fallback. It was confusing to get `UnitsNotFoundException` in this case, since case-insensitive usually works for most units. ### Changes - Handle this case and throw `AmbiguousUnitParseException` instead of `UnitNotFoundException` - Describe the case-insensitive units that matched - Fix existing test `Parse_WithMultipleCaseInsensitiveMatchesButNoExactMatches_ThrowsUnitNotFoundException` - Skip retrying with fallback culture if no specific `formatProvider` was given - Avoid some of the unnecessary array allocations Co-authored-by: Andreas Gullberg Larsen <[email protected]>
Fixes #1423
UnitParser.Parse<LengthUnit>("MM")
fails due to matching bothMegameter
andMillimeter
in case-insensitive matching, but matches neither of them in the case-sensitive fallback. It was confusing to getUnitsNotFoundException
in this case, since case-insensitive usually works for most units.Changes
AmbiguousUnitParseException
instead ofUnitNotFoundException
Parse_WithMultipleCaseInsensitiveMatchesButNoExactMatches_ThrowsUnitNotFoundException
formatProvider
was given