Skip to content

[util-dynamodb] "Uncaught SyntaxError" on unmarshalling floating point numbers outside SAFE_INTEGER bounds #2014

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

Closed
trivikr opened this issue Feb 10, 2021 · 1 comment · Fixed by #2015
Labels
bug This issue is a bug.

Comments

@trivikr
Copy link
Member

trivikr commented Feb 10, 2021

Describe the bug

util-dynamodb throws the following error when trying to unmarshall floating point numbers outside SAFE_INTEGER bounds:

Uncaught SyntaxError: Cannot convert -9007199254740998.25 to a BigInt

Your environment

SDK version number

@aws-sdk/[email protected]

Is the issue in the browser/Node.js/ReactNative?

All

Details of the browser/Node.js/ReactNative version

tested in Node.js v14.15.4

Steps to reproduce

Code
const { unmarshall } = require("@aws-sdk/util-dynamodb");
const number = unmarshall({ number: { N: "-9007199254740998.25" } });
console.log(number);

Observed behavior

/Users/trivikr/workspace/v2-vs-v3/node_modules/@aws-sdk/util-dynamodb/dist/cjs/convertToNative.js:50
            return BigInt(numString);
                   ^

SyntaxError: Cannot convert -9007199254740998.25 to a BigInt
    at BigInt (<anonymous>)
    at convertNumber (/Users/trivikr/workspace/v2-vs-v3/node_modules/@aws-sdk/util-dynamodb/dist/cjs/convertToNative.js:50:20)
    at Object.convertToNative (/Users/trivikr/workspace/v2-vs-v3/node_modules/@aws-sdk/util-dynamodb/dist/cjs/convertToNative.js:19:28)
    at /Users/trivikr/workspace/v2-vs-v3/node_modules/@aws-sdk/util-dynamodb/dist/cjs/convertToNative.js:67:20
    at Array.reduce (<anonymous>)
    at convertMap (/Users/trivikr/workspace/v2-vs-v3/node_modules/@aws-sdk/util-dynamodb/dist/cjs/convertToNative.js:65:58)
    at Object.convertToNative (/Users/trivikr/workspace/v2-vs-v3/node_modules/@aws-sdk/util-dynamodb/dist/cjs/convertToNative.js:27:28)
    at unmarshall (/Users/trivikr/workspace/v2-vs-v3/node_modules/@aws-sdk/util-dynamodb/dist/cjs/unmarshall.js:11:57)
    at Object.<anonymous> (/Users/trivikr/workspace/v2-vs-v3/documentClient.js:3:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)

Expected behavior

Throw an error, as the string value can't be converted into BigInt. But mention in the error that options.wrapNumbers=true can be set to get string value of the number.

Additional context

Noticed while debugging #1983

@trivikr trivikr added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 10, 2021
@trivikr trivikr removed the needs-triage This issue or PR still needs to be triaged. label Feb 10, 2021
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant