thecorecity / cognitum

A small Discord bot with statistics collection and useful utility features.
Apache License 2.0
13 stars 3 forks source link

Unhandled exception on `LogsProcessor` causing bot to restart #144

Closed koloml closed 2 years ago

koloml commented 2 years ago

Describe the bug Some error generated by discord.js causing bot to restart. Logs related to this crash are listed below:

Oct 10 13:26:00 Core node[774]: /opt/cognitum/node_modules/@sapphire/shapeshift/dist/index.js:1058
Oct 10 13:26:00 Core node[774]:     return Result.err(new CombinedError(errors));
Oct 10 13:26:00 Core node[774]:                       ^
Oct 10 13:26:00 Core node[774]: CombinedError: Received one or more errors
Oct 10 13:26:00 Core node[774]:     at UnionValidator.handle (/opt/cognitum/node_modules/@sapphire/shapeshift/dist/index.js:1058:23)
Oct 10 13:26:00 Core node[774]:     at UnionValidator.parse (/opt/cognitum/node_modules/@sapphire/shapeshift/dist/index.js:113:88)
Oct 10 13:26:00 Core node[774]:     at DefaultEmbed.setDescription (/opt/cognitum/node_modules/@discordjs/builders/dist/messages/embed/Embed.cjs:57:37)
Oct 10 13:26:00 Core node[774]:     at Object.msgdelete (/opt/cognitum/lib/classes/LogsProcessor.js:401:6)
Oct 10 13:26:00 Core node[774]:     at LogsProcessor.#handleEvent (/opt/cognitum/lib/classes/LogsProcessor.js:228:70)
Oct 10 13:26:00 Core node[774]:     at processTicksAndRejections (node:internal/process/task_queues:96:5) {
Oct 10 13:26:00 Core node[774]:   errors: [
Oct 10 13:26:00 Core node[774]:     ExpectedValidationError: Expected values to be equals
Oct 10 13:26:00 Core node[774]:         at LiteralValidator.handle (/opt/cognitum/node_modules/@sapphire/shapeshift/dist/index.js:699:76)
Oct 10 13:26:00 Core node[774]:         at LiteralValidator.run (/opt/cognitum/node_modules/@sapphire/shapeshift/dist/index.js:99:23)
Oct 10 13:26:00 Core node[774]:         at UnionValidator.handle (/opt/cognitum/node_modules/@sapphire/shapeshift/dist/index.js:1053:32)
Oct 10 13:26:00 Core node[774]:         at UnionValidator.parse (/opt/cognitum/node_modules/@sapphire/shapeshift/dist/index.js:113:88)
Oct 10 13:26:00 Core node[774]:         at DefaultEmbed.setDescription (/opt/cognitum/node_modules/@discordjs/builders/dist/messages/embed/Embed.cjs:57:37)
Oct 10 13:26:00 Core node[774]:         at Object.msgdelete (/opt/cognitum/lib/classes/LogsProcessor.js:401:6)
Oct 10 13:26:00 Core node[774]:         at LogsProcessor.#handleEvent (/opt/cognitum/lib/classes/LogsProcessor.js:228:70)
Oct 10 13:26:00 Core node[774]:         at processTicksAndRejections (node:internal/process/task_queues:96:5) {
Oct 10 13:26:00 Core node[774]:       validator: 's.literal(V)',
Oct 10 13:26:00 Core node[774]:       given: '',
Oct 10 13:26:00 Core node[774]:       expected: null
Oct 10 13:26:00 Core node[774]:     },
Oct 10 13:26:00 Core node[774]:     ExpectedConstraintError: Invalid string length
Oct 10 13:26:00 Core node[774]:         at Object.run (/opt/cognitum/node_modules/@sapphire/shapeshift/dist/index.js:1503:79)
Oct 10 13:26:00 Core node[774]:         at StringValidator.run (/opt/cognitum/node_modules/@sapphire/shapeshift/dist/index.js:103:27)
Oct 10 13:26:00 Core node[774]:         at UnionValidator.handle (/opt/cognitum/node_modules/@sapphire/shapeshift/dist/index.js:1053:32)
Oct 10 13:26:00 Core node[774]:         at UnionValidator.parse (/opt/cognitum/node_modules/@sapphire/shapeshift/dist/index.js:113:88)
Oct 10 13:26:00 Core node[774]:         at DefaultEmbed.setDescription (/opt/cognitum/node_modules/@discordjs/builders/dist/messages/embed/Embed.cjs:57:37)
Oct 10 13:26:00 Core node[774]:         at Object.msgdelete (/opt/cognitum/lib/classes/LogsProcessor.js:401:6)
Oct 10 13:26:00 Core node[774]:         at LogsProcessor.#handleEvent (/opt/cognitum/lib/classes/LogsProcessor.js:228:70)
Oct 10 13:26:00 Core node[774]:         at processTicksAndRejections (node:internal/process/task_queues:96:5) {
Oct 10 13:26:00 Core node[774]:       constraint: 's.string.lengthGreaterThanOrEqual',
Oct 10 13:26:00 Core node[774]:       given: '',
Oct 10 13:26:00 Core node[774]:       expected: 'expected.length >= 1'
Oct 10 13:26:00 Core node[774]:     }
Oct 10 13:26:00 Core node[774]:   ]
Oct 10 13:26:00 Core node[774]: }

Issue is caused by the code not checking for the empty message content and trying to pass empty string to the embed.

To Reproduce

  1. Send message with attachment and no text.
  2. Delete the message
  3. Bot crashes when trying to print information about deleted message.

Expected behavior

Screenshots

koloml commented 2 years ago

Investigated. Added more details.