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

BigInt wrapper used with decimals #73

Open
nicholaschiang opened this issue Apr 7, 2022 · 3 comments
Open

BigInt wrapper used with decimals #73

nicholaschiang opened this issue Apr 7, 2022 · 3 comments

Comments

@nicholaschiang
Copy link

When the useNativeBigInt option is enabled, this package attempts to wrap decimals (e.g. 0.990011990070343) in the native BigInt wrapper which fails (as they're obviously not integers). Instead, json-bigint should be smart enough to realize that a long floating point number is not an integer and thus should not be wrapped at all.

@nicholaschiang
Copy link
Author

Here's the error I'm encountering:

[dev:remix] SyntaxError: Cannot convert 0.990011990070343 to a BigInt
[dev:remix]     at BigInt (<anonymous>)
[dev:remix]     at number (/home/nchiang/repos/tweetscape/node_modules/json-bigint/lib/parse.js:215:15)
[dev:remix]     at value (/home/nchiang/repos/tweetscape/node_modules/json-bigint/lib/parse.js:397:41)
[dev:remix]     at object (/home/nchiang/repos/tweetscape/node_modules/json-bigint/lib/parse.js:367:27)
[dev:remix]     at value (/home/nchiang/repos/tweetscape/node_modules/json-bigint/lib/parse.js:389:16)
[dev:remix]     at array (/home/nchiang/repos/tweetscape/node_modules/json-bigint/lib/parse.js:314:22)
[dev:remix]     at value (/home/nchiang/repos/tweetscape/node_modules/json-bigint/lib/parse.js:391:16)
[dev:remix]     at /home/nchiang/repos/tweetscape/node_modules/json-bigint/lib/parse.js:410:14
[dev:remix]     at Array.parseJson (/home/nchiang/repos/tweetscape/app/db.server.ts:53:16)
[dev:remix]     at Result.parseRow (/home/nchiang/repos/tweetscape/node_modules/pg-promise/node_modules/pg/lib/result.js:68:38)
[dev:remix]     at Query.handleDataRow (/home/nchiang/repos/tweetscape/node_modules/pg-promise/node_modules/pg/lib/query.js:87:26)
[dev:remix]     at Client._handleDataRow (/home/nchiang/repos/tweetscape/node_modules/pg-promise/node_modules/pg/lib/client.js:345:22)
[dev:remix]     at Connection.emit (node:events:520:28)
[dev:remix]     at /home/nchiang/repos/tweetscape/node_modules/pg-promise/node_modules/pg/lib/connection.js:114:12
[dev:remix]     at Parser.parse (/home/nchiang/repos/tweetscape/node_modules/pg-protocol/src/parser.ts:104:9)
[dev:remix]     at Socket.<anonymous> (/home/nchiang/repos/tweetscape/node_modules/pg-protocol/src/index.ts:7:48)

@sidorares
Copy link
Owner

can you provide simple repro example?

@nicholaschiang
Copy link
Author

@sidorares I suspect this is actually already fixed in master:

          // Number with fractional part should be treated as number(double) including big integers in scientific notation, i.e 1.79e+308
          return _options.storeAsString
            ? string
            : /[\.eE]/.test(string)
            ? number
            : _options.useNativeBigInt
            ? BigInt(string)
            : new BigNumber(string);

It just hasn't been released to NPM yet (see #74) and thus I'm seeing this bug in production.

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

2 participants