Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed Field Value Exceeds Limit Causing Crash #224

Open
LamboCreeper opened this issue Mar 4, 2022 · 3 comments
Open

Embed Field Value Exceeds Limit Causing Crash #224

LamboCreeper opened this issue Mar 4, 2022 · 3 comments
Labels
accepted bug Something isn't working

Comments

@LamboCreeper
Copy link
Member

Overview

When a message is deleted or updated it triggers one of two handlers, these handlers take the contents of the original message and insert it into a field within an embed. However, the character limit of these fields is smaller than the limit of normal messages.

Expected Behaviour

A message containing more than 1024 characters gets trimmed to 1024 characters within the embed.

Actual Behaviour

A message containing more than 1024 characters causes the bot to crash.

2022-03-04T11:10:05.406066+00:00 app[worker.1]: DiscordAPIError: Invalid Form Body
2022-03-04T11:10:05.406066+00:00 app[worker.1]: embeds[0].fields[0].value: Must be 1024 or fewer in length.
2022-03-04T11:10:05.406067+00:00 app[worker.1]: at RequestHandler.execute (/app/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
2022-03-04T11:10:05.406068+00:00 app[worker.1]: at processTicksAndRejections (node:internal/process/task_queues:96:5)
2022-03-04T11:10:05.406069+00:00 app[worker.1]: at async RequestHandler.push (/app/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
2022-03-04T11:10:05.406070+00:00 app[worker.1]: at async TextChannel.send (/app/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:175:15)
2022-03-04T11:10:05.406070+00:00 app[worker.1]: at async Client.sendLog (/app/build/abstracts/LogMessageDeleteHandler.js:16:13)
2022-03-04T11:10:05.406070+00:00 app[worker.1]: at async Client.handle (/app/build/event/handlers/LogMessageSingleDeleteHandler.js:11:9)
@LamboCreeper LamboCreeper added the bug Something isn't working label Mar 4, 2022
@LamboCreeper
Copy link
Member Author

I believe this is also affecting the quote embeds.

@olivier-b-be
Copy link
Contributor

Done some small testing around myself, currently I've added a simple sliceToLength static function in the StringUtils class that will slice the given string if it exceeds the passed in number. Added a value for the embed field in config.json to get the max length of the field.

You'd lose info because the content of the field is simply being cut away, there's no real extra fancy stuff going around about not slicing in the middle of a word. And another thing is that this would need to be added to every embed.addField call (at least for dynamic content like the message content in Discord itself)

@ari-party
Copy link

Library throws an error, if not catched it will cause the process to end

process.on("uncaughtException", (err, origin) => { console.error(err, origin) }) is what you are looking for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants