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

Number comparison doesn't handle NaN #26

Open
henbr opened this issue Nov 10, 2020 · 2 comments
Open

Number comparison doesn't handle NaN #26

henbr opened this issue Nov 10, 2020 · 2 comments

Comments

@henbr
Copy link

henbr commented Nov 10, 2020

This function doesn't handle NaN https://github.com/promaster-sdk/property/blob/master/packages/property/src/utils/compare-utils.ts#L16

This will cause this code to throw even though it looks like it shouldn't

  const pvs1 = PropertyValueSet.setInteger("test", NaN, PropertyValueSet.Empty);
  const pvs2 = PropertyValueSet.setInteger("test", NaN, PropertyValueSet.Empty);
  if (!PropertyValueSet.equals(pvs1, pvs2)) {
    throw Error("pvs not equal");
  }
@jonaskello
Copy link
Member

@Jontem @AdamLuotonen Do you have an idea of how you would want this to work?

@AdamLuotonen
Copy link

I guess we should consider Infinity too in this discussion. Also, I think it should work the same way in Amount. Right now it is not clear what happens when you create an Amount of NaN or Infinity.

My first thought is that we should only allow values passing isFinite() in PVS, PF and Amounts. In general I think these values only arise due to some bug or missing data, and in those cases they are better represented by being absent in the PVS and checked using x=null in PF.

So unless there is some case where we need this distinction I think we should just throw an exception. Returning undefined from setInteger would probably not be a good user experience.

An alternative would be to not set the value at all and just return the original PVS. Maybe that would be too "quiet", but we could always log it to the console. This would help developers find these NaN/Infinity values and fix them. Any such values that slip through to production does not crash the whole program, they are just absent from the PVS. I think we already put some error to the log when we have invalid property filter syntax.

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

No branches or pull requests

3 participants