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-multiple-resolved wrongly reports reject in try/catch block #382

Closed
FloEdelmann opened this issue Oct 13, 2022 · 6 comments · Fixed by #384
Closed

no-multiple-resolved wrongly reports reject in try/catch block #382

FloEdelmann opened this issue Oct 13, 2022 · 6 comments · Fixed by #384
Labels

Comments

@FloEdelmann
Copy link

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

@ota-meshi
Copy link
Member

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.

@Romick2005
Copy link
Contributor

Same here
image

@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 6.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@burtek
Copy link

burtek commented May 18, 2023

@ota-meshi

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?

@sequencerr
Copy link

@ota-meshi

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)
}

@burtek
Copy link

burtek commented May 24, 2023

@sequencerr opened as new issue

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