Skip to content

Commit

Permalink
Crashes because of use of JSON.stringify in Codec module #614
Browse files Browse the repository at this point in the history
  • Loading branch information
gigobyte committed Jan 24, 2023
1 parent feb3b2d commit ea62f0a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Codec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ describe('Codec', () => {
})
expect(mockCodec.encode({} as any)).toEqual({})
})

test('bigint error reporting', () => {
expect(Codec.interface({ n: string }).decode({ b: BigInt(1) })).toEqual(
Left(
'Problem with property "n": it does not exist in received object {"b":"1"}'
)
)
})
})

describe('custom', () => {
Expand Down
5 changes: 4 additions & 1 deletion src/Codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ export const Codec = {
) {
return Left(
`Problem with property "${key}": it does not exist in received object ${JSON.stringify(
input
input,
(_, value) => {
return typeof value === 'bigint' ? value.toString() : value
}
)}`
)
}
Expand Down

0 comments on commit ea62f0a

Please sign in to comment.