`no-multiple-resolved` wrongly reports `reject` in try/catch block
FloEdelmann opened this issue ยท comments
Description
The new no-multiple-resolved
rule (#369) reports an error if resolve
is used in the try
block and reject
is used in the catch
block, even though they can't be both executed:
return new Promise((resolve, reject) => {
https.get(someUrl, response => {
response.on(`end`, async () => {
try {
await writeFile(someFilePath, someContents);
resolve();
}
catch (error) {
reject(error);
}
});
});
});
Steps to Reproduce
(see code above)
Expected behavior: No error, since resolve
is only called when the writeFile
call succeeds, and reject
is only called if the writeFile
call fails.
Actual behavior: The reject
call is reported:
Promise should not be resolved multiple times. Promise is potentially resolved
Versions
- Node version: 16.17.0
- ESLint version: 8.25.0
- eslint-plugin-promise version: 6.1.0
Additional Information
Repo to reproduce (but the rule is not enabled there yet):
https://github.com/OpenLightingProject/open-fixture-library/blob/6ee07f7a4a4be9907c1238531acd3ec0deeabdb3/plugins/qlcplus_4.12.2/exportTests/fixture-tool-validation.js#L81-L101
Thank you for posting issue.
It seems a bug. We can see it in an online demo I personally made. I will look for a way to fix it.
๐ This issue has been resolved in version 6.1.1 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐
try {
resolve(someThrowingFn())
} catch (error) {
reject(error)
}
still errors for me. It doesn't error if I do this:
try {
const data = someThrowingFn()
resolve(data)
} catch (error) {
reject(error)
}
But those two are identical and should behave same way?
try { resolve(someThrowingFn()) } catch (error) { reject(error) }still errors for me. It doesn't error if I do this:
try { const data = someThrowingFn() resolve(data) } catch (error) { reject(error) }But those two are identical and should behave same way?
yes, the same for me
try {
resolve({ data: await someThrowingFn() })
} catch (error) {
reject(error)
}
@sequencerr opened as new issue