Skip to content

Commit

Permalink
fix: throw more helpful error when downloading format from `getBasi…
Browse files Browse the repository at this point in the history
…cInfo()`

closes #704
  • Loading branch information
fent committed Sep 25, 2020
1 parent a9c4574 commit 0ecb0c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/util.js
Expand Up @@ -83,6 +83,9 @@ exports.sortFormats = (a, b) => {
*/
exports.chooseFormat = (formats, options) => {
if (typeof options.format === 'object') {
if (!options.format.url) {
throw Error('Invalid format given, did you use `ytdl.getInfo()`?');
}
return options.format;
}

Expand Down
8 changes: 8 additions & 0 deletions test/util-test.js
Expand Up @@ -241,6 +241,14 @@ describe('util.chooseFormat', () => {
const format = util.chooseFormat(sortedFormats, { format: formats[0] });
assert.strictEqual(format, formats[0]);
});

describe('from `getBasicInfo()`', () => {
it('Throws error', () => {
assert.throws(() => {
util.chooseFormat(sortedFormats, { format: formats.filter(format => !format.url)[0] });
}, /Invalid format given/);
});
});
});

describe('With filter given', () => {
Expand Down

0 comments on commit 0ecb0c4

Please sign in to comment.