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

Non-extensible rejections result in unhandled rejection #25

Open
openreply-dleinhaeuser opened this issue May 13, 2019 · 1 comment
Open

Comments

@openreply-dleinhaeuser
Copy link

If the input function somehow rejects with a non-object, decorateErrorWithCounts will throw an error which leads to an unhandled rejection.

Example:

const pRetry = require('./');

pRetry(() => Promise.reject(Object.preventExtensions(new Error())))
    .catch(console.error);

Expected result:
The retry handler treats the non-extendable like any other (minus the decorating of course).

Actual result:
An UnhandledPromiseRejectionWarning is generated, the code continues on neither the resolution nor the rejection path.

Generally the code seems to not be well defended against errors from unexpected sources. For example. throwing from the onFailedAttempt function would also result in an unhandled rejection.

@openreply-dleinhaeuser openreply-dleinhaeuser changed the title Non-object rejections result in unhandled rejection Non-extensible rejections result in unhandled rejection May 13, 2019
@schmiegelt
Copy link

As I had the same issue, I solved it by wrapping the actual function call in an own function. In there, the non-extendable error can be cought and replaced by an extendable one.

So, instead of

const response = await doSomething()

I created a new function

async function trySomething() {
    try {
        await doSomething()
        return "Success"
    }
    catch(e) {
        //console.log(e)
        throw(new Error("Could not do something"))
    }
}

and used this in the p-reply code

const run = async () => {
	const response = await trySomething()

	return response
};

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

No branches or pull requests

3 participants