Clearer error message for invalid UCUM units#76
Merged
Conversation
Owner
Author
|
Related: #75 (Fix decibel (dB) parsing of logarithmic units). The need for a clearer parse error surfaced while investigating the invalid |
5a3c6b0 to
9f26974
Compare
Invalid UCUM codes surfaced lark's raw UnexpectedInput, leaking grammar terminal names (ANNOTATION, EXPONENT, ...) and never stating that the unit is invalid. Add parse_ucum(), used by from_ucum and the preprocessor, which raises InvalidUcumError naming the unit and pointing at the failure. It subclasses LarkError so existing handlers keep working.
9f26974 to
10016c2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Invalid UCUM codes previously surfaced lark's raw parser error, which leaks grammar-internal terminal names (
ANNOTATION,EXPONENT, ...) and never states that the unit is invalid:This adds
parse_ucum()and anInvalidUcumError, used byfrom_ucum()anducum_preprocessor, producing a domain-focused message that names the unit and keeps the caret:Truncated input is reported too:
InvalidUcumErrorsubclasseslark.exceptions.LarkError, so existingexcept LarkErrorhandlers keep working. The interactive CLI is left as-is (it already catchesUnexpectedInput).Discovered while fixing #62 (the invalid
dB[mW]case).