cozy / cozy-emails

Email Client for Cozy
GNU Affero General Public License v3.0
66 stars 41 forks source link

Client exception: a.forEach is not a function #803

Open clochix opened 8 years ago

clochix commented 8 years ago

A user reports than when he tries to open the Email application, he only get a white page. Here's the error found inside its logs:

EROR +03583 controllers:activity { type: 'error',
  error:
   { msg: 'a.forEach is not a function',
     name: 'TypeError',
     full: 'TypeError: a.forEach is not a function',
     stack: 'TypeError: a.forEach is not a function\n    at https://antoine-2.cozycloud.cc/apps/emails/js/app.js:15:10228\n    at Array.forEach (native)\n    at t (https://antoine-2.cozycloud.cc/apps/emails/js/app.js:15:10160)\n    at Qe.de.withMutations (https://antoine-2.cozycloud.cc/apps/emails/js/vendor.js:10:7827)\n    at n (https://antoine-2.cozycloud.cc/apps/emails/js/app.js:15:10523)\n    at https://antoine-2.cozycloud.cc/apps/emails/js/app.js:15:10570\n    at https://antoine-2.cozycloud.cc/apps/emails/js/app.js:15:11336\n    at d (https://antoine-2.cozycloud.cc/apps/emails/js/vendor.js:1:807)\n    at h (https://antoine-2.cozycloud.cc/apps/emails/js/vendor.js:1:952)\n    at https://antoine-2.cozycloud.cc/apps/emails/js/vendor.js:1:738' },
  href: 'https://antoine-2.cozycloud.cc/apps/emails/' }
EROR +0001 controllers:activity TypeError: a.forEach is not a function
    at https://antoine-2.cozycloud.cc/apps/emails/js/app.js:15:10228
    at Array.forEach (native)
    at t (https://antoine-2.cozycloud.cc/apps/emails/js/app.js:15:10160)
    at Qe.de.withMutations (https://antoine-2.cozycloud.cc/apps/emails/js/vendor.js:10:7827)
    at n (https://antoine-2.cozycloud.cc/apps/emails/js/app.js:15:10523)
    at https://antoine-2.cozycloud.cc/apps/emails/js/app.js:15:10570
    at https://antoine-2.cozycloud.cc/apps/emails/js/app.js:15:11336
    at d (https://antoine-2.cozycloud.cc/apps/emails/js/vendor.js:1:807)
    at h (https://antoine-2.cozycloud.cc/apps/emails/js/vendor.js:1:952)
    at https://antoine-2.cozycloud.cc/apps/emails/js/vendor.js:1:738

Good luck!

clochix commented 8 years ago

This errors seems to happen when importing contacts. datapoints of some contacts is an object instead of an array, so we can't use forEach to iterate on it.

clochix commented 8 years ago

This affects 6 out the 18.268 contacts of this user. Here's one of them (anonymized):

{
   "n" : "Xxxxxx;Yyyyyy;;;",
   "datapoints" : {
      "0" : {
         "value" : "+33 1 00 00 00 00",
         "name" : "tel",
         "type" : "cell"
      }
   },
   "carddavuri" : "9ccf7dc5-b0f2-418c-adca-cde0b5c2a8cd.vcf",
   "_id" : "7acb5f78170d3d69e5cc406575b9bb51",
   "docType" : "contact",
   "_rev" : "1-9fc32691e80b7bf337d0f1f8eee4858e",
   "fn" : "Yyyyyy Xxxxxx"
}
m4dz commented 8 years ago

I think we should patch the contacts directly in the Contacts app to ensure the data typing.

@poupotte, @frankrousseau : It re-opens the conversation about sharing data between-apps: emails should probably not be allowed to get contacts itself from the DS but rather rely on a service in the DS which exposes contacts and ensure permissions (and eventually ensure data types like in this case), right?