Bug 1282130 - Improve error message for failing ICS import;r=philipp;a=philipp BETA_BASE_20160919
authormakemyday@gmx-topmail.de
Sun, 10 Jul 2016 15:44:32 +0200
changeset 22643 92018d3dc161b198867d57c8f488107b0ad24724
parent 22642 767d9f98e5e3a64232b0a994b6b9f0b34494a50b
child 22644 90250acf8723ef9bcafdf6dfd624da4a8e58f2ec
push id1828
push usermakemyday@gmx-topmail.de
push dateMon, 19 Sep 2016 09:17:07 +0000
treeherdercomm-aurora@92018d3dc161 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp, philipp
bugs1282130
Bug 1282130 - Improve error message for failing ICS import;r=philipp;a=philipp
calendar/base/content/import-export.js
calendar/base/src/calIcsParser.js
calendar/libical/src/libical/icalproperty.c
--- a/calendar/base/content/import-export.js
+++ b/calendar/base/content/import-export.js
@@ -77,32 +77,41 @@ function loadEventsFromFile(aCalendar) {
                                  .getService(Components.interfaces.calIImporter);
 
         const nsIFileInputStream = Components.interfaces.nsIFileInputStream;
         const nsIScriptableInputStream = Components.interfaces.nsIScriptableInputStream;
 
         let inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"]
                                     .createInstance(nsIFileInputStream);
         let items = [];
+        let exc;
 
         try {
             inputStream.init( fp.file, MODE_RDONLY, parseInt("0444", 8), {});
             items = importer.importFromStream(inputStream, {});
         } catch(ex) {
+            exc = ex;
             switch (ex.result) {
                 case Components.interfaces.calIErrors.INVALID_TIMEZONE:
-                    showError(calGetString("calendar", "timezoneError", [filePath]));
+                    showError(cal.calGetString("calendar", "timezoneError", [filePath]));
                     break;
                 default:
-                    showError(calGetString("calendar", "unableToRead") + filePath + "\n"+ ex);
+                    showError(cal.calGetString("calendar", "unableToRead") + filePath + "\n"+ ex);
             }
         } finally {
             inputStream.close();
         }
 
+        if (!items.length && !exc) {
+            // the ics did not contain any events, so there's no need to proceed. But we should
+            // notify the user about it at least in the log, if we haven't before.
+            cal.LOG("Failed to import from " + filePath + ". There are no importable items in this file.");
+            return;
+        }
+
         if (aCalendar) {
             putItemsIntoCal(aCalendar, items);
             return;
         }
 
         let calendars = cal.getCalendarManager().getCalendars({});
         calendars = calendars.filter(isCalendarWritable);
 
--- a/calendar/base/src/calIcsParser.js
+++ b/calendar/base/src/calIcsParser.js
@@ -35,18 +35,25 @@ calIcsParser.prototype = {
             if (rootComp.componentType == 'VCALENDAR') {
                 calComp = rootComp;
             } else {
                 calComp = rootComp.getFirstSubcomponent('VCALENDAR');
             }
         }
 
         if (!calComp) {
-            cal.ERROR("Parser Error. Could not find 'VCALENDAR' component: \n" +
-                      rootComp + "\nStack: \n" + cal.STACK(10));
+            let message = "Parser Error. Could not find 'VCALENDAR' component.\n";
+            try {
+                // we try to also provide the parsed component - if that fails due to an error in
+                // libical, we append the error message of the caught exception, which includes
+                // already a stack trace.
+                cal.ERROR(message + rootComp + "\n" + cal.STACK(10));
+            } catch(e) {
+                cal.ERROR(message + e);
+            }
         }
 
         let self = this;
         let state = new parserState(this, aAsyncParsing);
 
         while (calComp) {
             // Get unknown properties from the VCALENDAR
             for (let prop of cal.ical.propertyIterator(calComp)) {
--- a/calendar/libical/src/libical/icalproperty.c
+++ b/calendar/libical/src/libical/icalproperty.c
@@ -129,20 +129,22 @@ icalproperty_new (icalproperty_kind kind
 
     return (icalproperty*)icalproperty_new_impl(kind);
 }
 
 
 icalproperty*
 icalproperty_new_clone(icalproperty* old)
 {
-    icalproperty *new = icalproperty_new_impl(old->kind);
+    icalproperty *new;
     pvl_elem p;
 
     icalerror_check_arg_rz((old!=0),"old");
+
+    new = icalproperty_new_impl(old->kind);
     icalerror_check_arg_rz((new!=0),"new");
 
     if (old->value !=0) {
 	new->value = icalvalue_new_clone(old->value);
     }
 
     if (old->x_name != 0) {