-
Notifications
You must be signed in to change notification settings - Fork 228
Return error result when unit labels aren't matched during quantity parsing #8584
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
Conversation
I will highlight that none of our previous tests failed, there are no regressions so far, including this relevant test case where when a unitless format is passed in, the parser will use the first unit label that matches any known units for parsing
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves error handling in the quantity parser by returning explicit error results when unit labels cannot be matched to known units, replacing the previous silent failure behavior.
- Enhanced the
Parser.getDefaultUnitConversion
method to throw aQuantityError
when unit labels are present but unmatched - Updated the main parsing logic to catch these errors and return
ParseError.UnitLabelSuppliedButNotMatched
results - Added comprehensive test coverage for invalid unit label scenarios
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
core/quantity/src/Parser.ts | Added error throwing for unmatched unit labels and error handling in parsing logic |
core/quantity/src/test/Parsing.test.ts | Added test cases to verify proper error handling for invalid unit labels |
docs/changehistory/NextVersion.md | Documented the breaking change for enhanced error handling |
common/changes/@itwin/core-quantity/nam-parser-label-fix_2025-09-30-14-41.json | Added change log entry for the parser enhancement |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…js-core into nam/parser-label-fix
This pull request improves error handling in the
@itwin/core-quantity
package's quantity parser. The parser now returns an explicit error result when a unit label is supplied but cannot be matched to any known unit, rather than silently failing or accepting invalid labels. This is a breaking change that ensures more accurate feedback for consumers of the parsing API.Error handling improvements:
Parser
class now throws aQuantityError
withQuantityStatus.UnitLabelSuppliedButNotMatched
when unique unit labels are present but not matched to any known unit.ParseError.UnitLabelSuppliedButNotMatched
, ensuring callers receive a clear error when parsing fails due to unknown unit labels.Testing and documentation:
Parsing.test.ts
to verify that parsing with invalid unit labels returns the expected error.