cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From TanaseButcaru <...@git.apache.org>
Subject [GitHub] cordova-plugin-contacts pull request: [CB-11223] Better check for ...
Date Fri, 06 May 2016 21:54:20 GMT
Github user TanaseButcaru commented on a diff in the pull request:

    https://github.com/apache/cordova-plugin-contacts/pull/125#discussion_r62396222
  
    --- Diff: www/convertUtils.js ---
    @@ -28,10 +28,19 @@ module.exports = {
         */
         toCordovaFormat: function (contact) {
             var value = contact.birthday;
    -        try {
    -          contact.birthday = new Date(parseFloat(value));
    -        } catch (exception){
    -          console.log("Cordova Contact toCordovaFormat error: exception creating date.");
    +        if (value !== null) {
    +            try {
    +              contact.birthday = new Date(parseFloat(value));
    +              
    +              //we might get 'Invalid Date' which does not throw an error
    +              //and is an instance of Date.
    +              if (isNaN(contact.birthday.getTime())) {
    +                contact.birthday = null;
    --- End diff --
    
    The original logic was: try to get new date, if error, do nothing (so leave the contact.birthday
as it is).
    There is no problem with the original code, but it just not catches all errors and in
this case is the 'Invalid Date' error which never throws.
    The error I was getting on iOS was caused by a third party js lib that was iterating through
contact props, checking if the prop was an object and it was then was doing a toJSON() and
because contact.birthday was an object but in form of an error, that was the key element that
made safari throw an error. Firefox and Chrome does not throw an error if toJSON() is called
on an 'Invalid Date' object.
    
    So the error was indirectly caused by contacts plugin.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


Mime
View raw message