seishun / node-steam

Interface directly with Steam servers from Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Throw when accidentially passing SteamIDs as numbers

mk-pmb opened this issue · comments

commented

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.

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.

commented

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

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

commented

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

Challenge accepted.