From 8fb9b35fa49dd2c9ed9843ad944efcf584a8851d Mon Sep 17 00:00:00 2001 From: Skick Date: Sun, 5 Dec 2021 08:06:56 +0700 Subject: [PATCH 1/3] refactor(Error): `INVALID_TYPE` stringify what it got --- src/struct/DisTubeError.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/struct/DisTubeError.ts b/src/struct/DisTubeError.ts index ddc64e29..7688f248 100644 --- a/src/struct/DisTubeError.ts +++ b/src/struct/DisTubeError.ts @@ -2,15 +2,7 @@ const ERROR_MESSAGES = { INVALID_TYPE: (expected: (number | string) | readonly (number | string)[], got: any, name?: string) => `Expected ${ Array.isArray(expected) ? expected.map(e => (typeof e === "number" ? e : `'${e}'`)).join(" or ") : `'${expected}'` - }${name ? ` for '${name}'` : ""}, but got ${ - typeof got === "string" - ? `'${got}'` - : typeof got === "number" - ? got - : Array.isArray(got) - ? `Array<${got.length}>` - : got?.constructor?.name || typeof got - } (${typeof got})`, + }${name ? ` for '${name}'` : ""}, but got ${JSON.stringify(got)} (${got?.constructor?.name ?? typeof got})`, NUMBER_COMPARE: (name: string, expected: string, value: number) => `'${name}' must be ${expected} ${value}`, EMPTY_ARRAY: (name: string) => `'${name}' is an empty array`, EMPTY_FILTERED_ARRAY: (name: string, type: string) => `There is no valid '${type}' in the '${name}' array`, From 86fa4ff0b88b70d8c694530cfa8d2050279ace6a Mon Sep 17 00:00:00 2001 From: Skick Date: Tue, 14 Dec 2021 04:47:57 +0700 Subject: [PATCH 2/3] fix: new stream doesn't pause when `Queue#paused` is true Fixes #214 --- src/core/manager/QueueManager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/manager/QueueManager.ts b/src/core/manager/QueueManager.ts index 23f66651..72791d4f 100644 --- a/src/core/manager/QueueManager.ts +++ b/src/core/manager/QueueManager.ts @@ -143,8 +143,6 @@ export class QueueManager extends BaseManager { return true; } if (queue.stopped) return false; - queue.playing = true; - queue.paused = false; const song = queue.songs[0]; try { const { url, source, formats, streamURL } = song; @@ -163,6 +161,8 @@ export class QueueManager extends BaseManager { const stream = this.handler.createStream(queue); queue.voice.play(stream); song.streamURL = stream.url; + if (queue.stopped) queue.stop(); + else if (queue.paused) queue.voice.pause(); return false; } catch (e: any) { this._handlePlayingError(queue, e); From 5c7ea9e10e31a34b8a94459ee8be6c03ed58675a Mon Sep 17 00:00:00 2001 From: Skick Date: Tue, 14 Dec 2021 09:27:07 +0700 Subject: [PATCH 3/3] test: update tests --- src/core/__test__/DisTubeOptions.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/__test__/DisTubeOptions.test.ts b/src/core/__test__/DisTubeOptions.test.ts index cf9f9f48..c9e452d4 100644 --- a/src/core/__test__/DisTubeOptions.test.ts +++ b/src/core/__test__/DisTubeOptions.test.ts @@ -27,23 +27,23 @@ test("Validate DisTubeOptions", () => { const n: any = NaN; expect(() => { new Options(n); - }).toThrow("Expected 'object' for 'DisTubeOptions', but got NaN"); + }).toThrow("Expected 'object' for 'DisTubeOptions', but got null (Number)"); for (const key of Object.keys(defaultOptions).filter(o => o !== "plugins")) { const options = {}; options[key] = n; expect(() => { new Options(options); - }).toThrow(`Expected '${typeof defaultOptions[key]}' for 'DisTubeOptions.${key}', but got NaN`); + }).toThrow(`Expected '${typeof defaultOptions[key]}' for 'DisTubeOptions.${key}', but got null (Number)`); } expect(() => { new Options({ plugins: "undefined" as any }); - }).toThrow("Expected 'Array' for 'DisTubeOptions.plugins', but got 'undefined'"); + }).toThrow("Expected 'Array' for 'DisTubeOptions.plugins', but got \"undefined\" (String)"); expect(() => { new Options({ youtubeCookie: 1 as any }); - }).toThrow("Expected 'string' for 'DisTubeOptions.youtubeCookie', but got 1"); + }).toThrow("Expected 'string' for 'DisTubeOptions.youtubeCookie', but got 1 (Number)"); expect(() => { new Options({ youtubeIdentityToken: {} as any }); - }).toThrow("Expected 'string' for 'DisTubeOptions.youtubeIdentityToken', but got Object"); + }).toThrow("Expected 'string' for 'DisTubeOptions.youtubeIdentityToken', but got {} (Object)"); expect(() => { new Options({ invalidKey: "an invalid key" } as any); }).toThrow("'invalidKey' does not need to be provided in DisTubeOptions");