From ecaec29380d31dcd94a30b4242bf26c5e4c395f7 Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Tue, 27 Nov 2018 21:42:28 +0100 Subject: [PATCH] fix(Util): throw an explicit error if a chunk exceeds the max length (#2936) * fix(Util): throw an explicit error if a chunk exceeds the max length * refactor(Util): consolidate both errors in splitMessage into one * revert(Messages): do not unnecessarily change the error code * revert(Messages): do not remove the word 'the' --- src/errors/Messages.js | 4 +--- src/util/Util.js | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/errors/Messages.js b/src/errors/Messages.js index 1abdd4ca0..5f237ac5b 100644 --- a/src/errors/Messages.js +++ b/src/errors/Messages.js @@ -73,7 +73,7 @@ const Messages = { TYPING_COUNT: 'Count must be at least 1', - SPLIT_MAX_LEN: 'Message exceeds the max length and contains no split characters.', + SPLIT_MAX_LEN: 'Chunk exceeds the max length and contains no split characters.', BAN_RESOLVE_ID: (ban = false) => `Couldn't resolve the user ID to ${ban ? 'ban' : 'unban'}.`, @@ -81,8 +81,6 @@ const Messages = { SEARCH_CHANNEL_TYPE: 'Target must be a TextChannel, DMChannel, GroupDMChannel, or Guild.', - MESSAGE_SPLIT_MISSING: 'Message exceeds the max length and contains no split characters.', - GUILD_CHANNEL_RESOLVE: 'Could not resolve channel to a guild channel.', GUILD_VOICE_CHANNEL_RESOLVE: 'Could not resolve channel to a guild voice channel.', GUILD_CHANNEL_ORPHAN: 'Could not find a parent to this guild channel.', diff --git a/src/util/Util.js b/src/util/Util.js index 119d0c7c7..562b81a41 100644 --- a/src/util/Util.js +++ b/src/util/Util.js @@ -56,7 +56,7 @@ class Util { static splitMessage(text, { maxLength = 2000, char = '\n', prepend = '', append = '' } = {}) { if (text.length <= maxLength) return text; const splitText = text.split(char); - if (splitText.length === 1) throw new RangeError('SPLIT_MAX_LEN'); + if (splitText.some(chunk => chunk.length > maxLength)) throw new RangeError('SPLIT_MAX_LEN'); const messages = []; let msg = ''; for (const chunk of splitText) {