Continue promise.all loop if error caught in lambda node scenario












1















I have a simple node script run in AWS lambda function. Each promise is an AWS sdk call which can fail, but for the most part I want to ignore the failures and continue.



When I catch the error and just ignore it as follows, I get the UnhandledPromiseRejectionWarning error



Promise.all(promises).then(() => {
callback(null, 'completed');
}).catch(err => {
console.log('aws errors!', err);
});


Each promise is basically a putScheduledUpdateGroupAction call as follows



return new Promise((resolve, reject) => {
aws.putScheduledUpdateGroupAction(params, function(err, data) {
if (err) {
reject(err);
}
else {
resolve(data);
}
});
});


What needs to happen to ignore the AWS errors and continue without this rejection error ? I need it to continue in a lambda situation, not stand alone node.










share|improve this question

























  • Can you post a Minimal, Complete, and Verifiable example? Where does the error get thrown, exactly?

    – CertainPerformance
    Jan 1 at 22:40











  • @CertainPerformance I've added code for the promise created

    – yoyoma
    Jan 1 at 22:58











  • You should use the promisified variant of the AWS call. Simply return aws.putScheduledUpdateGroupAction(params).promise().

    – jarmod
    Jan 1 at 23:33
















1















I have a simple node script run in AWS lambda function. Each promise is an AWS sdk call which can fail, but for the most part I want to ignore the failures and continue.



When I catch the error and just ignore it as follows, I get the UnhandledPromiseRejectionWarning error



Promise.all(promises).then(() => {
callback(null, 'completed');
}).catch(err => {
console.log('aws errors!', err);
});


Each promise is basically a putScheduledUpdateGroupAction call as follows



return new Promise((resolve, reject) => {
aws.putScheduledUpdateGroupAction(params, function(err, data) {
if (err) {
reject(err);
}
else {
resolve(data);
}
});
});


What needs to happen to ignore the AWS errors and continue without this rejection error ? I need it to continue in a lambda situation, not stand alone node.










share|improve this question

























  • Can you post a Minimal, Complete, and Verifiable example? Where does the error get thrown, exactly?

    – CertainPerformance
    Jan 1 at 22:40











  • @CertainPerformance I've added code for the promise created

    – yoyoma
    Jan 1 at 22:58











  • You should use the promisified variant of the AWS call. Simply return aws.putScheduledUpdateGroupAction(params).promise().

    – jarmod
    Jan 1 at 23:33














1












1








1








I have a simple node script run in AWS lambda function. Each promise is an AWS sdk call which can fail, but for the most part I want to ignore the failures and continue.



When I catch the error and just ignore it as follows, I get the UnhandledPromiseRejectionWarning error



Promise.all(promises).then(() => {
callback(null, 'completed');
}).catch(err => {
console.log('aws errors!', err);
});


Each promise is basically a putScheduledUpdateGroupAction call as follows



return new Promise((resolve, reject) => {
aws.putScheduledUpdateGroupAction(params, function(err, data) {
if (err) {
reject(err);
}
else {
resolve(data);
}
});
});


What needs to happen to ignore the AWS errors and continue without this rejection error ? I need it to continue in a lambda situation, not stand alone node.










share|improve this question
















I have a simple node script run in AWS lambda function. Each promise is an AWS sdk call which can fail, but for the most part I want to ignore the failures and continue.



When I catch the error and just ignore it as follows, I get the UnhandledPromiseRejectionWarning error



Promise.all(promises).then(() => {
callback(null, 'completed');
}).catch(err => {
console.log('aws errors!', err);
});


Each promise is basically a putScheduledUpdateGroupAction call as follows



return new Promise((resolve, reject) => {
aws.putScheduledUpdateGroupAction(params, function(err, data) {
if (err) {
reject(err);
}
else {
resolve(data);
}
});
});


What needs to happen to ignore the AWS errors and continue without this rejection error ? I need it to continue in a lambda situation, not stand alone node.







node.js amazon-web-services promise






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 22:57







yoyoma

















asked Jan 1 at 22:39









yoyomayoyoma

71221125




71221125













  • Can you post a Minimal, Complete, and Verifiable example? Where does the error get thrown, exactly?

    – CertainPerformance
    Jan 1 at 22:40











  • @CertainPerformance I've added code for the promise created

    – yoyoma
    Jan 1 at 22:58











  • You should use the promisified variant of the AWS call. Simply return aws.putScheduledUpdateGroupAction(params).promise().

    – jarmod
    Jan 1 at 23:33



















  • Can you post a Minimal, Complete, and Verifiable example? Where does the error get thrown, exactly?

    – CertainPerformance
    Jan 1 at 22:40











  • @CertainPerformance I've added code for the promise created

    – yoyoma
    Jan 1 at 22:58











  • You should use the promisified variant of the AWS call. Simply return aws.putScheduledUpdateGroupAction(params).promise().

    – jarmod
    Jan 1 at 23:33

















Can you post a Minimal, Complete, and Verifiable example? Where does the error get thrown, exactly?

– CertainPerformance
Jan 1 at 22:40





Can you post a Minimal, Complete, and Verifiable example? Where does the error get thrown, exactly?

– CertainPerformance
Jan 1 at 22:40













@CertainPerformance I've added code for the promise created

– yoyoma
Jan 1 at 22:58





@CertainPerformance I've added code for the promise created

– yoyoma
Jan 1 at 22:58













You should use the promisified variant of the AWS call. Simply return aws.putScheduledUpdateGroupAction(params).promise().

– jarmod
Jan 1 at 23:33





You should use the promisified variant of the AWS call. Simply return aws.putScheduledUpdateGroupAction(params).promise().

– jarmod
Jan 1 at 23:33












1 Answer
1






active

oldest

votes


















2














Update:



To ignore any failed promise, using Promise.all(promises).catch() should catch everything.



Original answer:



If you want to ignore failures of specific promises (not all), you can put a .catch() handler in each one.



return aws.putScheduledUpdateGroupAction(params).promise().catch((err) => {
// Log the error but don't throw.
console.log(err)
})





share|improve this answer


























  • Shouldn't the Promise.all's catch handle it though? jsfiddle.net/oLz5bvpa

    – CertainPerformance
    Jan 2 at 2:04











  • thanks but I was hoping to fix my existing code before I change the call to .promise() for the moment

    – yoyoma
    Jan 2 at 2:57











  • Promise.all's catch should handle it without the need to put a catch in each one. Can you share a complete example @yoyoma? If you log the value of err in your putScheduledUpdateGroupAction handler function do you see anything logged? My guess is the error you are seeing came from somewhere else.

    – Jaime
    Jan 2 at 16:46













  • Right. Promise.all's catch catches everything. Clarified it in my answer.

    – dashmug
    Jan 2 at 23:31











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999499%2fcontinue-promise-all-loop-if-error-caught-in-lambda-node-scenario%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Update:



To ignore any failed promise, using Promise.all(promises).catch() should catch everything.



Original answer:



If you want to ignore failures of specific promises (not all), you can put a .catch() handler in each one.



return aws.putScheduledUpdateGroupAction(params).promise().catch((err) => {
// Log the error but don't throw.
console.log(err)
})





share|improve this answer


























  • Shouldn't the Promise.all's catch handle it though? jsfiddle.net/oLz5bvpa

    – CertainPerformance
    Jan 2 at 2:04











  • thanks but I was hoping to fix my existing code before I change the call to .promise() for the moment

    – yoyoma
    Jan 2 at 2:57











  • Promise.all's catch should handle it without the need to put a catch in each one. Can you share a complete example @yoyoma? If you log the value of err in your putScheduledUpdateGroupAction handler function do you see anything logged? My guess is the error you are seeing came from somewhere else.

    – Jaime
    Jan 2 at 16:46













  • Right. Promise.all's catch catches everything. Clarified it in my answer.

    – dashmug
    Jan 2 at 23:31
















2














Update:



To ignore any failed promise, using Promise.all(promises).catch() should catch everything.



Original answer:



If you want to ignore failures of specific promises (not all), you can put a .catch() handler in each one.



return aws.putScheduledUpdateGroupAction(params).promise().catch((err) => {
// Log the error but don't throw.
console.log(err)
})





share|improve this answer


























  • Shouldn't the Promise.all's catch handle it though? jsfiddle.net/oLz5bvpa

    – CertainPerformance
    Jan 2 at 2:04











  • thanks but I was hoping to fix my existing code before I change the call to .promise() for the moment

    – yoyoma
    Jan 2 at 2:57











  • Promise.all's catch should handle it without the need to put a catch in each one. Can you share a complete example @yoyoma? If you log the value of err in your putScheduledUpdateGroupAction handler function do you see anything logged? My guess is the error you are seeing came from somewhere else.

    – Jaime
    Jan 2 at 16:46













  • Right. Promise.all's catch catches everything. Clarified it in my answer.

    – dashmug
    Jan 2 at 23:31














2












2








2







Update:



To ignore any failed promise, using Promise.all(promises).catch() should catch everything.



Original answer:



If you want to ignore failures of specific promises (not all), you can put a .catch() handler in each one.



return aws.putScheduledUpdateGroupAction(params).promise().catch((err) => {
// Log the error but don't throw.
console.log(err)
})





share|improve this answer















Update:



To ignore any failed promise, using Promise.all(promises).catch() should catch everything.



Original answer:



If you want to ignore failures of specific promises (not all), you can put a .catch() handler in each one.



return aws.putScheduledUpdateGroupAction(params).promise().catch((err) => {
// Log the error but don't throw.
console.log(err)
})






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 2 at 23:30

























answered Jan 1 at 23:52









dashmugdashmug

6,7091942




6,7091942













  • Shouldn't the Promise.all's catch handle it though? jsfiddle.net/oLz5bvpa

    – CertainPerformance
    Jan 2 at 2:04











  • thanks but I was hoping to fix my existing code before I change the call to .promise() for the moment

    – yoyoma
    Jan 2 at 2:57











  • Promise.all's catch should handle it without the need to put a catch in each one. Can you share a complete example @yoyoma? If you log the value of err in your putScheduledUpdateGroupAction handler function do you see anything logged? My guess is the error you are seeing came from somewhere else.

    – Jaime
    Jan 2 at 16:46













  • Right. Promise.all's catch catches everything. Clarified it in my answer.

    – dashmug
    Jan 2 at 23:31



















  • Shouldn't the Promise.all's catch handle it though? jsfiddle.net/oLz5bvpa

    – CertainPerformance
    Jan 2 at 2:04











  • thanks but I was hoping to fix my existing code before I change the call to .promise() for the moment

    – yoyoma
    Jan 2 at 2:57











  • Promise.all's catch should handle it without the need to put a catch in each one. Can you share a complete example @yoyoma? If you log the value of err in your putScheduledUpdateGroupAction handler function do you see anything logged? My guess is the error you are seeing came from somewhere else.

    – Jaime
    Jan 2 at 16:46













  • Right. Promise.all's catch catches everything. Clarified it in my answer.

    – dashmug
    Jan 2 at 23:31

















Shouldn't the Promise.all's catch handle it though? jsfiddle.net/oLz5bvpa

– CertainPerformance
Jan 2 at 2:04





Shouldn't the Promise.all's catch handle it though? jsfiddle.net/oLz5bvpa

– CertainPerformance
Jan 2 at 2:04













thanks but I was hoping to fix my existing code before I change the call to .promise() for the moment

– yoyoma
Jan 2 at 2:57





thanks but I was hoping to fix my existing code before I change the call to .promise() for the moment

– yoyoma
Jan 2 at 2:57













Promise.all's catch should handle it without the need to put a catch in each one. Can you share a complete example @yoyoma? If you log the value of err in your putScheduledUpdateGroupAction handler function do you see anything logged? My guess is the error you are seeing came from somewhere else.

– Jaime
Jan 2 at 16:46







Promise.all's catch should handle it without the need to put a catch in each one. Can you share a complete example @yoyoma? If you log the value of err in your putScheduledUpdateGroupAction handler function do you see anything logged? My guess is the error you are seeing came from somewhere else.

– Jaime
Jan 2 at 16:46















Right. Promise.all's catch catches everything. Clarified it in my answer.

– dashmug
Jan 2 at 23:31





Right. Promise.all's catch catches everything. Clarified it in my answer.

– dashmug
Jan 2 at 23:31




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999499%2fcontinue-promise-all-loop-if-error-caught-in-lambda-node-scenario%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

A Topological Invariant for $pi_3(U(n))$