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

5.1.0 - Each then() should return a value or throw #213

Closed
hawkeye64 opened this issue Apr 19, 2021 · 6 comments · Fixed by #363
Closed

5.1.0 - Each then() should return a value or throw #213

hawkeye64 opened this issue Apr 19, 2021 · 6 comments · Fixed by #363
Labels

Comments

@hawkeye64
Copy link

Updated deps this morning. In particular, eslint-plugin-promise from v4.3.1 to v5.1.0 (did you forget to make a tag for this release?) and getting the following error:

error  Each then() should return a value or throw  promise/always-return

The code in question looks like this:

export const fetchAbout = async function ({ commit, state, getters, rootState }) {
  return axios.get(state.baseUrl)
    .then((results) => {
      if (results.status === 200) { // OK
        commit('setAbout', results.data.payload)
        return results
      }
      else {
        throw new Error(results.data.error || results.data)
      }
    })
    .catch(function (error) {
      console.error('fetch about', error)
      throw error
    })
}

I am not seeing the issue here. There is both a return and a throw involved.
Expected behavior: No error here

Actual behavior: issues an error

Versions

  • Node version: v12.18.4
  • ESLint version: v7.23.0
  • eslint-plugin-promise version: v5.1.0
@hawkeye64
Copy link
Author

Anyone care to comment? Is the above code incorrect? If so, what would be the best procedure for handling this so the eslint-plugin-promise doesn't complain?

@Tol1
Copy link

Tol1 commented Jun 9, 2021

I believe this is a bug in plugin. I get this same error if return/throw contains an expression, just like you have inside your error constructor (results.data.error || results.data)

@xjamundx
Copy link
Contributor

xjamundx commented Jun 9, 2021

I can try to take a look at this this week.

@mlippert
Copy link

I'm still seeing this issue in ver 6.0.0
The line reported in error has a logical expression like @Tol1 reported above in the construction of a literal object
and the character in the line is the d of data.title

    title: data.title || data.room,

which is an argument to a function call that returns a Promise at the beginning of a .then chain which is returned inside another .then function.

Versions

  • Node version: v16.13.2
  • ESLint version: v8.7.0
  • eslint-plugin-promise version: v6.0.0

eslint-plugin-promise v4.3.1 does not have this issue.

@mwmcode
Copy link

mwmcode commented Aug 23, 2022

This is a bug 🐛 (still present in v.6.0.0)

As @Tol1 , if you remove the expression inside Error() the error would go away!

promise-err

as a temp work around:

const errMsg = json?.error_description || 'Error';
throw new Error(errMsg);

@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 6.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

5 participants