Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Parser emits number for delete events, which get rounded to numbers beyond MAX_SAFE_INTEGER #34

Open
fasiha opened this issue Sep 1, 2023 · 0 comments

Comments

@fasiha
Copy link

fasiha commented Sep 1, 2023

I was debugging why I was being notified of deleted statuses whose IDs I didn't recognize. For example, I received the following payload from the mastodon-api message listener:

{ event: 'delete', data: 110988663231921360 }

Note that this is a number (even though Mastodon streaming API docs claim it should be a string ID). However, if in parser.js I console.log the raw message, here's what it receives:

event: delete\ndata: 110988663231921363\n\n

110988663231921363 (≈2**56.623) is bigger than MAX_SAFE_INTEGER so it gets rounded to the value coming out of the message listener:

> parseInt('110988663231921363')
110988663231921360

Note how the two numbers above aren't the same.


Do you have any tips on how the parser should be modified to handle this special case? Should we have a list of events that need to be treated as strings (like delete) and pass that through as-is without any JSON decoding?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant