Skip to content
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

The decimal's range should not be parsed if parsing fraction digits fails #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fredgan
Copy link
Contributor

@fredgan fredgan commented Nov 11, 2020

No description provided.

@coveralls
Copy link

coveralls commented Nov 11, 2020

Coverage Status

Coverage increased (+0.3%) to 76.357% when pulling 18da630 on fredgan:decimal-type-resolve-optimization into 88fe1d5 on openconfig:master.

@@ -280,7 +280,8 @@ check:
y.IdentityBase = resolvedBase.Identity
}

if t.Range != nil {
// If parsing fractionDigits fails, the ranges should not be parsed
if t.Range != nil && isDecimal64 && y.FractionDigits != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check that the logic here is right? I think integer types may also have a range that isn't nil, but this resolution of the range is now only implemented for decimal64. If we could add a testcase to ensure that this is properly covered (and demonstrate that we didn't break this) that'd be great.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, parsing the range of integer types is ignored, I've adjusted the logic and added a testcase.

@fredgan fredgan force-pushed the decimal-type-resolve-optimization branch from c0ea443 to 18da630 Compare November 12, 2020 06:51
Comment on lines -283 to +284
if t.Range != nil {
// If parsing fraction-digits of type decimal64 fails, the range should not be parsed
if t.Range != nil && (!isDecimal64 || (isDecimal64 && y.FractionDigits != 0)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseRanges already error checks where FractionDigits is 0 (via decimalValueFromString), so I'm wondering if it's actually better to keep the current behaviour and error out, instead of silently allowing parsing to continue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goyang/pkg/yang/types.go

Lines 247 to 250 in fd7d014

case isDecimal64:
// If we are directly of type decimal64 then we must specify
// fraction-digits in the range from 1-18.
i, err := t.FractionDigits.asRangeInt(1, 18)

In fact, the value 0 indicates that the FractionDigits value has already failed to be parsed (via asRangeInt).

If continue to parse, parserRanges checks the error value 0 as FractionDigits, then reports an unreasonable error msg bad range: invalid number of fraction digits 0: out of range [1..18], and the new testcase also fails because two errors are generated, so I think the value 0 needs to be excluded.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Makes sense.

@wenovus
Copy link
Collaborator

wenovus commented Jul 21, 2021

I think this is reasonable to add, although I would want to wait until an integration test is added, which should be simple once #188 is merged. If that checks out then LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants