seishun / node-steam

Interface directly with Steam servers from Node.js
MIT License
1k stars 180 forks source link

Throw when accidentially passing SteamIDs as numbers #433

Closed mk-pmb closed 5 years ago

mk-pmb commented 6 years ago

Since JS numbers are too small to convey SteamIDs, I'd expect all functions to throw if I accidentially pass a number instead of a string. The current behavior, silently carrying on with a rounded version of the number, is one of the worst strategies I could imagine.

andrewda commented 6 years ago

Yes, though it would be better to check to make sure it's not a number instead of checking if it is a string.

if (typeof steamID === 'number') {
  throw('Dangerous use of number for steamID.')
}

This will ensure the use of a Long (from bytebuffer, which this library uses) is still allowed, in addition to a SteamID class.

mk-pmb commented 6 years ago

I'd be ok with the more strict type check as well. Catching the number mistake is just the minimum safeguard. :-)

seishun commented 5 years ago

It's not really possible to add checks in every method since they just pass objects to Protobuf.js in most handlers.

mk-pmb commented 5 years ago

It's not really possible to add checks in every method

Challenge accepted.