eilvelia / tdl

Node.js bindings to TDLib 🥒
MIT License
394 stars 52 forks source link

Invalid user identifier #167

Closed jonasbpa closed 1 month ago

jonasbpa commented 1 month ago

I'm receiving an error every now and then in some of my clients. I have not seen this error documented anywhere (either here or tdlib/td) and I was not able to recognize any pattern that throws this error. It seems random to me.

{"type":"TDLibError","message":"Invalid user identifier","stack":"TDLibError: Invalid user identifier\n at Client._handleReceive (/dist/node_modules/tdl/dist/client.js:532:30)\n at Client.handleReceive (/dist/node_modules/tdl/dist/client.js:513:18)\n at Client._loop (/dist/nodemodules/tdl/dist/client.js:502:22)","":"error","code":400,"name":"TDLibError"}

eilvelia commented 1 month ago

You're passing an incorrect id to TDLib somehow.

The error is set in either /td/telegram/UserManager.cpp#L3942 or /td/telegram/UserManager.cpp#L3977.

That is, the UserId::is_valid check fails, which is defined as follows:

  bool is_valid() const {
    return 0 < id && id <= MAX_USER_ID;
  }

and MAX_USER_ID is defined as 2⁴⁰-1 on the latest TDLib.

Perhaps you might be confusing the kind of identifier beginning in -100... with user_id.

jonasbpa commented 1 month ago

Thank you so much for your clarification. With your direction, I was able to find where the issue could happen, and avoid it if it ever is to happen. The only problem I had with it was that the session was lost whenever the error happened.