Skip to content

Commit

Permalink
refactor: create dump file on error for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
skick1234 committed Nov 20, 2023
1 parent 458492d commit e37d755
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ const main = module.exports = async (searchString, options, rt = 3) => {
resp.items.push(...nestedResp);
return resp;
} catch (e) {
throw new Error('No result!');
parsed.query = searchString;
UTIL.logger(parsed);
throw new Error(e);
}
};

Expand Down
17 changes: 17 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { request } = require('undici');
const PATH = require('path');
const FS = require('fs');

const BASE_URL = 'https://www.youtube.com/';
const DEFAULT_OPTIONS = { limit: 10, safeSearch: false };
Expand Down Expand Up @@ -253,3 +255,18 @@ const setPropInsensitive = (obj, prop, value) => {
obj[key || prop] = value;
return key;
};

exports.logger = content => {
const dir = PATH.resolve(__dirname, '../dumps/');
const file = PATH.resolve(dir, `${Math.random().toString(36).substr(3)}-${Date.now()}.txt`);
const cfg = PATH.resolve(__dirname, '../package.json');
const bugsRef = require(cfg).bugs.url;

if (!FS.existsSync(dir)) FS.mkdirSync(dir);
FS.writeFileSync(file, JSON.stringify(content));
console.error(`\n/${'*'.repeat(200)}`);
console.error('Unsupported YouTube Playlist response.');
console.error(`Please post the the files in ${dir} to DisTube support server or ${bugsRef}. Thanks!`);
console.error(`${'*'.repeat(200)}\\`);
return null;
};

0 comments on commit e37d755

Please sign in to comment.