From 583e04d7c0835b89610687317d1a3a5bf79d11c8 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Wed, 10 Feb 2021 04:26:52 +0000 Subject: [PATCH 1/2] fix(util-dynamodb): update error when using BigInt for unmarshalling --- packages/util-dynamodb/src/convertToNative.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/util-dynamodb/src/convertToNative.ts b/packages/util-dynamodb/src/convertToNative.ts index a0251b396b83..27a4c76c789c 100644 --- a/packages/util-dynamodb/src/convertToNative.ts +++ b/packages/util-dynamodb/src/convertToNative.ts @@ -50,7 +50,11 @@ const convertNumber = (numString: string, options?: unmarshallOptions): number | const infinityValues = [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY]; if ((num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) && !infinityValues.includes(num)) { if (typeof BigInt === "function") { - return BigInt(numString); + try { + return BigInt(numString); + } catch (error) { + throw new Error(`${numString} can't be converted to BigInt. Set options.wrapNumbers to get string value.`); + } } else { throw new Error(`${numString} is outside SAFE_INTEGER bounds. Set options.wrapNumbers to get string value.`); } From b3e017df225ca357fd9cf8f07bad545af5883cc2 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Wed, 10 Feb 2021 04:37:19 +0000 Subject: [PATCH 2/2] test: throws if number cannot be converted into BigInt --- packages/util-dynamodb/src/convertToNative.spec.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/util-dynamodb/src/convertToNative.spec.ts b/packages/util-dynamodb/src/convertToNative.spec.ts index 487b2a69cfe0..abf90b717e59 100644 --- a/packages/util-dynamodb/src/convertToNative.spec.ts +++ b/packages/util-dynamodb/src/convertToNative.spec.ts @@ -86,6 +86,14 @@ describe("convertToNative", () => { ); }); }); + + [`${Number.MAX_SAFE_INTEGER + 2}.1`, `${Number.MIN_SAFE_INTEGER - 2}.1`].forEach((numString) => { + it(`throws if number cannot be converted into BigInt: ${numString}`, () => { + expect(() => { + convertToNative({ N: numString }); + }).toThrowError(`${numString} can't be converted to BigInt. Set options.wrapNumbers to get string value.`); + }); + }); }); describe("binary", () => {