SinisterRectus / Discordia

Discord API library written in Lua for the Luvit runtime environment
MIT License
697 stars 143 forks source link

HTTP Requests seem to not return an error yet discordia returns nil #335

Open TheFortex opened 2 years ago

TheFortex commented 2 years ago

This hasn't been an issue for the first month or so when my bot was hosted but then it just showed up out of nowhere and I've tried going around the issue by retrying to send the request if it returns nil but that came up with another issue where sometimes for example when sending a message the message would get sent in discord but not returned so the bot sends it again

take for example this request: client:getChannel(data.jobChannels[channels[channel]]):getMessages(100) It works fine most of the time but then randomly it will just return nil for no reason and the logs have no http errors at all. Is this an issue in discordia or from discord's side or just a network issue?

Bilal2453 commented 2 years ago

It works fine most of the time but then randomly it will just return nil for no reason and the logs have no http errors at all

It can be still an HTTP error without it printing that into the console, for example, when the logger level is lower than needed. To make sure if it is erroring or it is some bug, Discordia will always return nil, err_msg on similar errors, see that second return value for further info. From your description although, it does not seem to be a bug, just an HTTP error that is not being logged.

TheFortex commented 2 years ago

my logger level is debug

Bilal2453 commented 2 years ago

Note: After a conversation on Discord regarding this, I've advised @TheFortex to manually update http-codec. I was suspecting that one of the recently fixed bugs in http-codec was causing some of the packets to be dropped client side.

I am waiting until it is confirmed to fix this issue here, assuming it was indeed a bug.

Bilal2453 commented 2 years ago

According to @TheFortex this seem to be solved by just using the newer http-codec.

@SinisterRectus we might want to release the http-codec fix faster and start using it by Discordia 2. Not sure how wide this issue is, but it probably is affecting a lot of people.

Blizihguh commented 1 year ago

Having what looks to be the same issue here -- once in a blue moon, I have the bot send a message, and it shows up in Discord, but the send() call returns nil with the error "http-codec.lua:256: chunk-size field too large." Should I just update http-codec.lua, then? (ie, from here?)

Edit: Was able to hunt down the replacement file in Discord. (In case anybody needs it: it wasn't there, it was here). Given that the code is only running about a dozen times a week, and the error only seems to happen once every few dozen runs, it'll probably be a while before I can say with confidence whether or not it helped.

Bilal2453 commented 1 year ago

http-codec has been updated on Lit very recently, all you need to do is delete it from your deps folder and re-install it with lit install. It took a while for the fix to be pushed to Lit and, it got fixed in the Lit's Github repo since a year now. The one used in the Luvit repo is a major version behind so don't use that.

By the way, you can easily know where a Lit module was sourced from if you refer to https://luvit.io/lit.html and search the module.