parse-community / parse-server-push-adapter

A push notification adapter for Parse Server
https://parseplatform.org
MIT License
87 stars 99 forks source link

throw _iteratorError #62

Closed funkenstrahlen closed 6 years ago

funkenstrahlen commented 7 years ago

I am running version 1.2.0 of parse-server-push-adapter. I added osx push config to my server configuration. Now the app crashes on startup with throw _iteratorError.

2017-03-14T14:56:39.663970+00:00 heroku[web.1]: Starting process with command `npm start`
2017-03-14T14:56:42.403842+00:00 app[web.1]:
2017-03-14T14:56:42.403855+00:00 app[web.1]: > podlive-parse-server@1.4.0 start /app
2017-03-14T14:56:42.403856+00:00 app[web.1]: > node index.js
2017-03-14T14:56:42.403857+00:00 app[web.1]:
2017-03-14T14:56:44.369047+00:00 app[web.1]:
2017-03-14T14:56:44.369063+00:00 app[web.1]: /app/node_modules/parse-server-push-adapter/lib/ParsePushAdapter.js:81
2017-03-14T14:56:44.369064+00:00 app[web.1]:           throw _iteratorError;
2017-03-14T14:56:44.369065+00:00 app[web.1]:           ^
2017-03-14T14:56:44.369066+00:00 app[web.1]: [object Object]
2017-03-14T14:56:44.383983+00:00 app[web.1]:
2017-03-14T14:56:44.394205+00:00 app[web.1]: npm ERR! Linux 3.13.0-112-generic
2017-03-14T14:56:44.394396+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-03-14T14:56:44.394542+00:00 app[web.1]: npm ERR! node v7.7.2
2017-03-14T14:56:44.394668+00:00 app[web.1]: npm ERR! npm  v4.1.2
2017-03-14T14:56:44.394837+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-03-14T14:56:44.395060+00:00 app[web.1]: npm ERR! podlive-parse-server@1.4.0 start: `node index.js`
2017-03-14T14:56:44.395160+00:00 app[web.1]: npm ERR! Exit status 1
2017-03-14T14:56:44.395291+00:00 app[web.1]: npm ERR!
2017-03-14T14:56:44.395379+00:00 app[web.1]: npm ERR! Failed at the podlive-parse-server@1.4.0 start script 'node index.js'.
2017-03-14T14:56:44.395468+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-03-14T14:56:44.395560+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the podlive-parse-server package,
2017-03-14T14:56:44.395649+00:00 app[web.1]: npm ERR! not with npm itself.
2017-03-14T14:56:44.395744+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-03-14T14:56:44.395831+00:00 app[web.1]: npm ERR!     node index.js
2017-03-14T14:56:44.395920+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-03-14T14:56:44.396011+00:00 app[web.1]: npm ERR!     npm bugs podlive-parse-server
2017-03-14T14:56:44.396098+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-03-14T14:56:44.396186+00:00 app[web.1]: npm ERR!     npm owner ls podlive-parse-server
2017-03-14T14:56:44.396275+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-03-14T14:56:44.405248+00:00 app[web.1]:
2017-03-14T14:56:44.405608+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-03-14T14:56:44.405803+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2017-03-14T14:56:46.493610+00:00 heroku[web.1]: State changed from starting to crashed
2017-03-14T14:56:46.483890+00:00 heroku[web.1]: Process exited with status 1

This is how my push config does look like:

  push: {
    ios: {
      pfx: __dirname + '/certs/' + process.env.APNS_IOS_CERTIFICATE, // The filename of private key and certificate in PFX or PKCS12 format from disk  
      bundleId: process.env.BUNDLE_ID_IOS, // The bundle identifier associate with your app
      production: is_production // Specifies which environment to connect to: Production (if true) or Sandbox
    },
    osx: {
      pfx: __dirname + '/certs/' + process.env.APNS_OSX_CERTIFICATE, // The filename of private key and certificate in PFX or PKCS12 format from disk  
      bundleId: process.env.BUNDLE_ID_OSX, // The bundle identifier associate with your app
      production: is_production // Specifies which environment to connect to: Production (if true) or Sandbox
    }
  },

All configuration variables are set.

Expected:

parse server push adapter should throw an error that osx is unsupported push type as this is only supported with release 1.3.0.

Actual result:

It crashes with throw _iteratorError;.

thoughts:

I think _iteratorError in this case is actually the correct error I expect (throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED, 'Push to ' + pushType + ' is not supported');. However parse server does not print the error correctly to the user as you can see here: https://github.com/ParsePlatform/parse-server/blob/c1dcaf12712eb025d502387e564d3b9c1093a768/src/Adapters/AdapterLoader.js

Therefore I never see the actual error message. Maybe this is an error of parse-server in this case.

flovilmart commented 7 years ago

parse server push adapter should throw an error that osx is unsupported push type as this is only supported with release 1.3.0.

Yeah not really, that would imply releasing a 1.2.1 with that ;)

funkenstrahlen commented 7 years ago
      if (this.validPushTypes.indexOf(pushType) < 0) {
        throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED,
                              'Push to ' + pushType + ' is not supported');
      }

This is already present in 1.2.0.

flovilmart commented 7 years ago

Shouldn't the push config be:

push: {
    ios:[{
      pfx: __dirname + '/certs/' + process.env.APNS_IOS_CERTIFICATE, // The filename of private key and certificate in PFX or PKCS12 format from disk  
      bundleId: process.env.BUNDLE_ID_IOS, // The bundle identifier associate with your app
      production: is_production // Specifies which environment to connect to: Production (if true) or Sandbox
    }],
    osx: [{
      pfx: __dirname + '/certs/' + process.env.APNS_OSX_CERTIFICATE, // The filename of private key and certificate in PFX or PKCS12 format from disk  
      bundleId: process.env.BUNDLE_ID_OSX, // The bundle identifier associate with your app
      production: is_production // Specifies which environment to connect to: Production (if true) or Sandbox
    }]
  },
funkenstrahlen commented 7 years ago

It does support array or no array:

  let apnsArgsList = [];
  if (Array.isArray(args)) {
    apnsArgsList = apnsArgsList.concat(args);
  } else if (typeof args === 'object') {
    apnsArgsList.push(args);
  } else {
    throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED,
                          'APNS Configuration is invalid');
  }

So leaving the array away as I only have one certificate per deviceType is valid. It makes no difference to the error message if I add the arrays to the push config (just tried that).

flovilmart commented 7 years ago

uhh that's odd...

funkenstrahlen commented 7 years ago

I think _iteratorError is created by this code:

    try {
      for (var _iterator = pushTypes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var pushType = _step.value;

        if (this.validPushTypes.indexOf(pushType) < 0) {
          throw new _parse2.default.Error(_parse2.default.Error.PUSH_MISCONFIGURED, 'Push to ' + pushTypes + ' is not supported');
        }
        switch (pushType) {
          case 'ios':
          case 'tvos':
          case 'osx':
            this.senderMap[pushType] = new _APNS2.default(pushConfig[pushType]);
            break;
          case 'android':
          case 'fcm':
            this.senderMap[pushType] = new _GCM2.default(pushConfig[pushType]);
            break;
        }
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.return) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }
  }

This is in lib/ParsePushAdapter.js.

funkenstrahlen commented 7 years ago

I know there will be no problem with osx after 1.3.0 release. However this is an issue affecting all misconfigured push configurations.

MamdouhSar commented 7 years ago

I am facing the same problem with ios push notification,

push: {
    ios:
      [{
        pfx: __dirname  + process.env.CERT_PATH, // Dev PFX or P12
        bundleId: process.env.BUNDLE_ID,
        passphrase: process.env.CERT_PASSPHRASE,
        production: true
      }]
 }

Here's the error

parse-server-push-adapter/lib/ParsePushAdapter.js:81
          throw _iteratorError;
          ^
[object Object]
flovilmart commented 7 years ago

Seems to be a problem with the babel bump

funkenstrahlen commented 7 years ago

If I remove the osx push configuration and use it like @MamdouhSar I do not see this error!

  push: {
    ios: {
      pfx: __dirname + '/certs/' + process.env.APNS_IOS_CERTIFICATE, // The filename of private key and certificate in PFX or PKCS12 format from disk  
      bundleId: process.env.BUNDLE_ID_IOS, // The bundle identifier associate with your app
      production: is_production // Specifies which environment to connect to: Production (if true) or Sandbox
    }
    // ,osx: {
    //   pfx: __dirname + '/certs/' + process.env.APNS_OSX_CERTIFICATE, // The filename of private key and certificate in PFX or PKCS12 format from disk  
    //   bundleId: process.env.BUNDLE_ID_OSX, // The bundle identifier associate with your app
    //   production: is_production // Specifies which environment to connect to: Production (if true) or Sandbox
    // }
  }

So maybe there is some other issue with the configuration of @MamdouhSar but the error message is not displayed correctly due to babel?

flovilmart commented 7 years ago

Perhaps an issue with babel, let's see if we can either fix it or remove babel altogether :)

kelset commented 7 years ago

Any update on this?

flovilmart commented 6 years ago

please update to the latest version of parse-server and open a new issue if needed.