Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throws a "UnhandledPromiseRejectionWarning: TypeError [ERR_UNESCAPED_CHARACTERS]" when trying to search for Chinese, Japanese, Hebrew, or Arabic lyrics #5

Closed
LittleWhole opened this issue Jun 28, 2020 · 8 comments

Comments

@LittleWhole
Copy link

I tried to search for Chinese, Japanese, Hebrew, and Arabic lyrics, but when doing so, I get a UnhandledPromiseRejectionWarning: TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters.

Here's a log:

2020-06-28T06:47:53.331907+00:00 app[worker.1]: (node:23) UnhandledPromiseRejectionWarning: TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters

2020-06-28T06:47:53.331916+00:00 app[worker.1]:     at new ClientRequest (_http_client.js:151:13)

2020-06-28T06:47:53.331917+00:00 app[worker.1]:     at Object.request (https.js:310:10)

2020-06-28T06:47:53.331917+00:00 app[worker.1]:     at RedirectableRequest._performRequest (/app/node_modules/follow-redirects/index.js:169:24)

2020-06-28T06:47:53.331918+00:00 app[worker.1]:     at new RedirectableRequest (/app/node_modules/follow-redirects/index.js:66:8)

2020-06-28T06:47:53.331918+00:00 app[worker.1]:     at Object.wrappedProtocol.request (/app/node_modules/follow-redirects/index.js:307:14)

2020-06-28T06:47:53.331919+00:00 app[worker.1]:     at dispatchHttpRequest (/app/node_modules/genius-lyrics-api/node_modules/axios/lib/adapters/http.js:179:25)

2020-06-28T06:47:53.331919+00:00 app[worker.1]:     at new Promise (<anonymous>)

2020-06-28T06:47:53.331919+00:00 app[worker.1]:     at httpAdapter (/app/node_modules/genius-lyrics-api/node_modules/axios/lib/adapters/http.js:21:10)

2020-06-28T06:47:53.331920+00:00 app[worker.1]:     at dispatchRequest (/app/node_modules/genius-lyrics-api/node_modules/axios/lib/core/dispatchRequest.js:52:10)

2020-06-28T06:47:53.331920+00:00 app[worker.1]:     at runMicrotasks (<anonymous>)

2020-06-28T06:47:53.331920+00:00 app[worker.1]: (Use `node --trace-warnings ...` to show where the warning was created)

2020-06-28T06:47:53.331950+00:00 app[worker.1]: (node:23) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)

2020-06-28T06:47:53.331991+00:00 app[worker.1]: (node:23) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.```
@farshed
Copy link
Owner

farshed commented Jun 28, 2020

@LittleWhole can you provide an example of the song you were trying to search?

@LittleWhole
Copy link
Author

LittleWhole commented Jun 28, 2020

@farshed Sure!

Chinese: https://genius.com/Pu-shu--lyrics

Japanese: https://genius.com/Mrs-green-apple-tenbyou-no-uta-lyrics

By the way, I should probably clarify that I am using the getLyrics() function, not the searchSong() function, sorry

@farshed
Copy link
Owner

farshed commented Jun 28, 2020

@LittleWhole I cannot reproduce this. getLyrics method works fine with both URLs and returns the correct lyrics.

Can you share some more info like code samples and lib version?

@LittleWhole
Copy link
Author

LittleWhole commented Jun 28, 2020

@farshed

Lib version: 3.0.1

Code context: This is a lyrics command in a Discord bot.

const genius = require('genius-lyrics-api');
const Discord = require('discord.js')

exports.run = async (client, message, command, args, perms, config) => {
    let thisConnection = client.voice.connections.find(connection => connection.channel.guild === message.guild)
    let songInfo = thisConnection.dispatcher.songInfo();
    let options = {
        apiKey: config.apikeys.genius,
        title: songInfo.title,
        artist: "",
        optimizeQuery: true
    }
    genius.getLyrics(options).then((lyrics) => {
        let lyricsEmbed;
        for (let i = 0; i < lyrics.length; i += 2048) {
            const toSend = lyrics.substring(i, Math.min(lyrics.length, i + 2048));
            lyricsEmbed = new Discord.MessageEmbed()
            .setDescription(toSend)
            .setColor(config.colors.blue);
            message.channel.send({ embed: lyricsEmbed });
        }
    });
};

@farshed
Copy link
Owner

farshed commented Jun 28, 2020

@LittleWhole what's the value of songInfo.title? Also can you attach a catch method with the getLyrics call and confirm that the error is being thrown by getLyrics and not something else in your code?

@LittleWhole
Copy link
Author

LittleWhole commented Jun 28, 2020

@farshed
In this test, songInfo.title should be 朴樹 - 平凡之路 [歌詞字幕][電影《後會無期》主題曲][完整高清音質] The Continent Theme Song - The Ordinary Road (Pu Shu).
Here's the catch output of the error:

2020-06-28T14:19:02.960979+00:00 app[worker.1]: TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters

2020-06-28T14:19:02.960995+00:00 app[worker.1]:     at new ClientRequest (_http_client.js:151:13)

2020-06-28T14:19:02.960996+00:00 app[worker.1]:     at Object.request (https.js:310:10)

2020-06-28T14:19:02.960996+00:00 app[worker.1]:     at RedirectableRequest._performRequest (/app/node_modules/follow-redirects/index.js:169:24)

2020-06-28T14:19:02.960997+00:00 app[worker.1]:     at new RedirectableRequest (/app/node_modules/follow-redirects/index.js:66:8)

2020-06-28T14:19:02.960997+00:00 app[worker.1]:     at Object.wrappedProtocol.request (/app/node_modules/follow-redirects/index.js:307:14)

2020-06-28T14:19:02.960998+00:00 app[worker.1]:     at dispatchHttpRequest (/app/node_modules/genius-lyrics-api/node_modules/axios/lib/adapters/http.js:179:25)

2020-06-28T14:19:02.961000+00:00 app[worker.1]:     at new Promise (<anonymous>)

2020-06-28T14:19:02.961000+00:00 app[worker.1]:     at httpAdapter (/app/node_modules/genius-lyrics-api/node_modules/axios/lib/adapters/http.js:21:10)

2020-06-28T14:19:02.961001+00:00 app[worker.1]:     at dispatchRequest (/app/node_modules/genius-lyrics-api/node_modules/axios/lib/core/dispatchRequest.js:52:10)

2020-06-28T14:19:02.961001+00:00 app[worker.1]:     at runMicrotasks (<anonymous>) {

2020-06-28T14:19:02.961002+00:00 app[worker.1]:   code: 'ERR_UNESCAPED_CHARACTERS'

2020-06-28T14:19:02.961003+00:00 app[worker.1]: }

@farshed
Copy link
Owner

farshed commented Jun 28, 2020

The error is caused by the presence of special characters like [ and ] in the title. I've released a patch which encodes these special characters before making a request.

Do note that searching 朴樹 - 平凡之路 [歌詞字幕][電影《後會無期》主題曲][完整高清音質] The Continent Theme Song - The Ordinary Road (Pu Shu) on genius.com doesn't return any results so the lib will return null. See https://genius.com/search?q=%E6%9C%B4%E6%A8%B9%20-%20%E5%B9%B3%E5%87%A1%E4%B9%8B%E8%B7%AF%20%5B%E6%AD%8C%E8%A9%9E%E5%AD%97%E5%B9%95%5D%5B%E9%9B%BB%E5%BD%B1%E3%80%8A%E5%BE%8C%E6%9C%83%E7%84%A1%E6%9C%9F%E3%80%8B%E4%B8%BB%E9%A1%8C%E6%9B%B2%5D%5B%E5%AE%8C%E6%95%B4%E9%AB%98%E6%B8%85%E9%9F%B3%E8%B3%AA%5D%20The%20Continent%20Theme%20Song%20-%20The%20Ordinary%20Road%20

@LittleWhole
Copy link
Author

@farshed Thank you, I understand 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants