How I Fixed: uncaught at check call: argument [object Promise] is not a function

Earlier this month I started dabbling with Redux Sagas as an alternative to Redux Thunks.

At the time I was highly skeptical – largely around whether re-writing a significant portion of my JavaScript was good use of my time, given that I had no prior experience with generators, and that conceptually sagas sounded pretty hard.

But I kept hitting issues with Thunks. They just seemed so cumbersome, and error prone. I found writing tests for them to be painful, and adding in the Redux API Middleware made that even more complicated.

Ultimately, switching to Redux Saga has been one of the highlights of my current project. I love it. Every problem I have had so far has been made easier through the use of sagas.

But today I hit on a problem I haven’t seen before:

uncaught at check call: argument [object Promise] is not a function

This is a generic version of the code I am using:

export function *doRequestProfile(action) {

  try {

    yield put({
      type: types.REQUEST__STARTED,
      payload: {
        requestFrom: 'my-saga'
      }
    });

    const profile = yield call(api.fetchProfile(action.payload.accountId));

    yield put({
       type: types.PROFILE__SUCCESSFULLY_RECEIVED,
       payload: {
         profile
       }
    });

  } catch (e) {

    yield put({
      type: types.PROFILE__FAILED_RECEIVING,
      payload: {
        message: e.message,
        statusCode: e.statusCode
      }
    });

  } finally {

    yield put({
      type: types.REQUEST__FINISHED,
      payload: {
        requestFrom: 'my-saga'
      }
    });

  }
}

export function *watchRequestProfile() {
  yield* takeLatest(types.PROFILE__REQUESTED, doRequestProfile);
}

I have highlighted the problematic line.

The issue here is that the error in the browser is fairly cryptic. It took me digging into the source code to figure this one out.

But actually the issue is really simple to fix.

The highlighted line above should be :

const profile = yield call(api.fetchProfile, action.payload.accountId);

I was calling my function myself, and then passing the promise on to the Saga… whoopsie daisy.

Published by

Code Review

CodeReviewVideos is a video training site helping software developers learn Symfony faster and easier.

42 thoughts on “How I Fixed: uncaught at check call: argument [object Promise] is not a function”

  1. Thanks. You saved me some time as well !
    Additional tip: if you need to pass more than one parameter to the function, consider passing an array of arguments… 😉

  2. Came here to say thank you. I was still partially in thunk-mode and didn’t realize the call effect takes the function and then variables as parameters.

  3. Wow, thanks. I was looking at that problem, totally lost and not looking forwards to doing the digging myself. Put in the error and your article popped up. Thanks!

  4. Just to let you know that you save my life LoL…I also just started with saga and seeing this “fix” I remembered right way of the docs and I see how dumb I was being hahahaa

    thanks!

    1. Seems they have changed the docs URL structure.

      AFAIK (and I use this every day atm), the “fix” is still the same. It’s not a fix. It’s an improper method call – was never a bug in their code, rather a fault of mine.


      // wrong
      call(api.fetchProfile(action.payload.accountId));

      // right
      call(api.fetchProfile, action.payload.accountId);

      // for clarity
      call(yourMethod, firstParam, secondParam, thirdParam, etc);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.