Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

UnhandledPromiseRejectionWarning + async problems #124

Open
snoitallicso opened this issue Sep 27, 2021 · 1 comment
Open

UnhandledPromiseRejectionWarning + async problems #124

snoitallicso opened this issue Sep 27, 2021 · 1 comment
Labels

Comments

@snoitallicso
Copy link

Nodejs version: v14.17.6

I'm using standard code from the docs:

const ytpl = require('ytpl');

const firstResultBatch = await ytpl('UU_aEa8K-EOJ3D6gOs7HcyNg', { pages: 1 });
const secondResultBatch = ytpl.continueReq(firstResultBatch.continuation);
const thirdResultBatch = ytpl.continueReq(secondResultBatch.continuation);

// You can now use the .items property of all result batches e.g.:
console.log(firstResultBatch.items);
console.log(secondResultBatch.items);
console.log(thirdResultBatch.items);`

SyntaxError: await is only valid in async function

ok then I rewtire 3 line without await (sure dumb solution but it work)

const firstResultBatch = await ytpl('UU_aEa8K-EOJ3D6gOs7HcyNg', { pages: 1 });

and got a new errors

undefined
undefined
undefined
(node:15049) UnhandledPromiseRejectionWarning: Error: invalid continuation array
    at AsyncFunction.main.continueReq (/home/dev/node_modules/ytpl/lib/main.js:131:56)
    at Object.<anonymous> (/home/dev/Documents/getplaylist.js:4:32)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47
(Use `node --trace-warnings ...` to show where the warning was created)
(node:15049) 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: 1)
(node:15049) [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.
(node:15049) UnhandledPromiseRejectionWarning: Error: invalid continuation array
    at AsyncFunction.main.continueReq (/home/dev/node_modules/ytpl/lib/main.js:131:56)
    at Object.<anonymous> (/home/dev/Documents/getplaylist.js:5:31)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47
(node:15049) 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: 2)
@TimeForANinja
Copy link
Owner

🤔 looks like the example for ytpl.continueReq is invalid
that function should return a promise and therefor also require a promise
e.g.:

const ytpl = require('ytpl');

const firstResultBatch = await ytpl('UU_aEa8K-EOJ3D6gOs7HcyNg', { pages: 1 });
const secondResultBatch = await ytpl.continueReq(firstResultBatch.continuation);
const thirdResultBatch = await ytpl.continueReq(secondResultBatch.continuation);

// You can now use the .items property of all result batches e.g.:
console.log(firstResultBatch.items);
console.log(secondResultBatch.items);
console.log(thirdResultBatch.items);

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

No branches or pull requests

2 participants