twilio-node
twilio-node copied to clipboard
Could you replace "q" to Promise es6?
@rgnevashev Are you having trouble using the q library? We could migrate over to using native promises but haven't had much feedback or other compelling reasons to warrant the work so far. We are certainly open to this if there is enough user demand.
@efossier yes, I have the issue with q lib. Im using native promise lib and my code doesnt work properly. async/await feature doesnt work as well. I sure, the change to native promise doesnt take much time
https://github.com/twilio/twilio-node/blob/master/lib/base/RequestClient.js#L61
@rgnevashev ok, I've created a ticket internally to track this work. It may be awhile until we have the bandwidth to pick this up however, do you have a work around you can use in the meantime?
we get a lot of errors from /app/node_modules/q/q.js:876
I am having trouble with the same lines as @davidchl. I get an error in the terminal:
Error: Authenticate
@efossier Is this something that's still being looked into?
Upon further review, I am not having trouble with the q library, itself. I made a mistake when matching up my account sid and auth tokens, and this is why I saw this error. My code is working now, and I can send messages. @davidchl maybe you already checked this, but it might be worth confirming that the account sid and auth token are from your normal account, not the test account. I ran into trouble with the test account, too.
@efossier @kyle-hall
Hi all, We've been getting the q errors from reservation.js
Note that we modified the q.js to the catch 2001 errors and not allow it to propagate because it causes our server to restart:
function Promise_rethrow(error) {
console.log('-----------');
console.log(error);
console.log('-----------');
if (error.code === 20001) { // causes server to restart
return;
}
throw error;
}
Here's the trace:
at Object.opts.done (/app/node_modules/twilio/lib/rest/taskrouter/v1/workspace/task/reservation.js:190:18)
at Pending_become_eachMessage_task (/app/node_modules/q/q.js:1377:30)
at RawTask.call (/app/node_modules/asap/asap.js:40:19)
at Pending_become_eachMessage_task (/app/node_modules/q/q.js:1377:30)
at RawTask.call (/app/node_modules/asap/asap.js:40:19)
at onComplete (/app/node_modules/twilio/lib/rest/taskrouter/v1/workspace/task/reservation.js:110:14)
at Rejected_dispatch [as dispatch] (/app/node_modules/q/q.js:1319:23)
at Promise_done_rejected (/app/node_modules/q/q.js:861:26)
at /app/node_modules/twilio/lib/rest/taskrouter/v1/workspace/task/reservation.js:243:16
at flush (/app/node_modules/asap/raw.js:50:29)
at Promise_done_rejected (/app/node_modules/q/q.js:861:26)
at flush (/app/node_modules/asap/raw.js:50:29)
at process._tickCallback (internal/process/next_tick.js:61:11)
at Promise_then_rejected (/app/node_modules/q/q.js:779:43)
at process._tickCallback (internal/process/next_tick.js:61:11)
at Rejected_then [as then] (/app/node_modules/q/q.js:1331:23)
at Rejected_then [as then] (/app/node_modules/q/q.js:1331:23)
at Deferred.modifiedReject [as reject] (/app/bin/q.ts:15:15)
[object Object]
at Rejected_dispatch [as dispatch] (/app/node_modules/q/q.js:1319:23)
at Promise_then_rejected (/app/node_modules/q/q.js:779:43)
at Deferred.modifiedReject [as reject] (/app/bin/q.ts:15:15)
[object Object]
The q.ts is our file and we just use it for logging the q errors.
Any ideas on what the issue could be?
Thanks, David
twilio-node constantly gives us UnhandledPromiseRejectionWarning that traces down to q.js. See the stack trace below:
(/app/node_modules/twilio/lib/rest/taskrouter/v1/workspace/task/reservation.js:190:18)
at onComplete (/app/node_modules/twilio/lib/rest/taskrouter/v1/workspace/task/reservation.js:110:14)
at Promise_then_rejected (/app/node_modules/q/q.js:779:43)
at Promise_done_rejected (/app/node_modules/q/q.js:861:26)
at Rejected_then [as then] (/app/node_modules/q/q.js:1323:23)
at Rejected_dispatch [as dispatch] (/app/node_modules/q/q.js:1311:23)
at Pending_become_eachMessage_task (/app/node_modules/q/q.js:1369:30)
at RawTask.call (/app/node_modules/asap/asap.js:40:19)
at flush (/app/node_modules/asap/raw.js:50:29)
at process._tickCallback (internal/process/next_tick.js:61:11)
(node:54) UnhandledPromiseRejectionWarning
(node:54) 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(). (rejection id: 1351)
(node:54) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1351)
From the error description, it sounds like twilio-node is not handling the promise rejection properly. This is causing us a lot of headache please help.
I tried the method described here to get around the issue, but that didn't fix it!
process.on('unhandledRejection', (reason, promise) => {
logger.error('Unhandled Promise Rejection at:', reason.stack || reason);
});
This is still in the backlog and will require a major version bump and doc updates. More +1s on the issue (not on comments) will help move it up.
Is it still open?
@gagandeepp Yes, still open. I did a POC for making the switch here: https://github.com/twilio/twilio-node/pull/450
But as mentioned above, this will require a MV bump and we'll probably want to do that with other breaking changes.
Even though this would require a MV bump, I'd consider this a security requirement for some of Twilio's customers. The q version & library in use here is about 6 years old and makes use of weak-map which has not been updated in 6 years either. Unmaintained and inactive dependencies impose a severe security risk for some companies.
Any way to accelerate this procedure?
Bumping this again. Continuing the use of non-native promises indefinitely is going to continue confusing developers and inject unexpected bugs. I respect this being a MV breaking change, but it's been years since native Promises were introduced.
I just ran into an issue with this as well. Attempting to do await twilioClient.messages.create({...}); resulted in hung code. My workaround was just to abandon the client as all I needed was messaging:
var response = await axios.post(`https://api.twilio.com/2010-04-01/Accounts/${smsAccountSid}/Messages.json`,
`From=${encodeURIComponent(process.env.TWILIO_FROM)}&To=${encodeURIComponent(toNumber)}&Body=${encodeURIComponent(message)}`,
{
auth: {
username: smsAccountSid,
password: smsAuthToken
}
});
return response;
Also seeing this - my application hangs when doing most twilio API calls. I'm using a pretty standard typescript project on v14 of node and it makes this library unusable for me.
NodeJS has had native support for promises dating back to 2015 and async/await in 2017. Given that I'm not sure why this dependency is still used five years later. Our issue with it is that the q.js library is obscuring our stack traces.
We're currently working on a 4.0 release candidate that will migrate to async/await promises.
@childish-sambino great to hear! Thanks for the update.
Closing as fixed (lastly) by https://github.com/twilio/twilio-node/pull/826
This will be included in the first release candidate for twilio-node@v4 dropping in a week.