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

no-callback-in-async-function rule? #155

Open
xjamundx opened this issue Jan 16, 2019 · 2 comments
Open

no-callback-in-async-function rule? #155

xjamundx opened this issue Jan 16, 2019 · 2 comments

Comments

@xjamundx
Copy link
Contributor

Putting callback code inside of async functions like this can lead to a lot of trouble:

async function bigProbs() {
    doSomething(function(err) {
        if (err) throw err; // won't be caught by the parent
        // ...
    })
}
@Lonniebiz
Copy link

Lonniebiz commented Jul 25, 2020

Would something like this address the issue:

async function bigProbs() {
	try
	{
		doSomething(function(err) {
			if (err) throw err; // won't be caught by the parent
			// ...
		})
	}
	catch(e)
	{
		throw(e);
	}
}

If so, can you not warn when the try catch is throwing to the parent?

@brettz9
Copy link
Member

brettz9 commented Jul 20, 2024

Would something like this address the issue:

async function bigProbs() {
	try
	{
		doSomething(function(err) {
			if (err) throw err; // won't be caught by the parent
			// ...
		})
	}
	catch(e)
	{
		throw(e);
	}
}

If so, can you not warn when the try catch is throwing to the parent?

No, your example is equivalent.

I think the intent is to avoid confusion by preventing what could admittedly even be synchronous callbacks (whose errors could actually work here). But it avoids confusion for cases where it really is asynchronous and then the error won't be caught.

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

4 participants