[Calendar] Constructor of CalendarAlarm should not throw an exception.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Fri, 4 Sep 2015 08:11:48 +0000 (10:11 +0200)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Fri, 4 Sep 2015 08:11:48 +0000 (10:11 +0200)
Fixes: XWALK-769
[Verification] TCT pass rate (r38): 100% (354/354/0/0/0)

Change-Id: I55b2f30d9c6b1ce4cd961b13ac752bf807d0b7f0
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/calendar/calendar_item.cc
src/calendar/js/calendar_alarm.js

index 5f59ab0f6981dae42419f1c973827e676433b122..9bdaeab83fca89558ce46764b120ac05182919b2 100755 (executable)
@@ -1092,9 +1092,15 @@ PlatformResult CalendarItem::AlarmsFromJson(int type, calendar_record_h rec,
       }
     }
 
+    const auto it_method = obj.find("method");
+    std::string method = "unknown";
+
+    if (obj.end() != it_method && it_method->second.is<std::string>()) {
+      method = it_method->second.get<std::string>();
+    }
+
     PlatformResult status =
-        SetEnum(alarm, _calendar_alarm.action, kAlarmMethod,
-                common::FromJson<std::string>(obj, "method"));
+        SetEnum(alarm, _calendar_alarm.action, kAlarmMethod, method);
     if (status.IsError()) {
       LoggerE("Error: %s", status.message().c_str());
       return status;
index 4f7c1272908cfe557445f53264ab47c3bd39e6b3..08c2638643687ca92081ed874edd46c4558c1f3a 100755 (executable)
@@ -24,8 +24,15 @@ var CalendarAlarm = function(time, method, description) {
 
   var _absoluteDate = time instanceof tizen.TZDate && !this.before ? time : null;
   var _before = time instanceof tizen.TimeDuration && !this.absoluteDate ? time : null;
-  var _method = converter_.toEnum(method, Object.keys(AlarmMethod), false);
   var _description = (description) ? converter_.toString(description, true) : '';
+  var _method;
+
+  try {
+    _method = converter_.toEnum(method, Object.keys(AlarmMethod), false);
+  } catch (e) {
+    console.warn('Failed to convert method: "' + method + '" to enum AlarmMethod.');
+    _method = method;
+  }
 
   Object.defineProperties(this, {
     absoluteDate: {