From 8778d82bcf0290e9f6a3f09bcc3e77d492cebdb2 Mon Sep 17 00:00:00 2001 From: sam detweiler Date: Tue, 15 Oct 2024 10:01:46 -0500 Subject: [PATCH 1/7] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 22b3274..7d1a280 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "dependencies": { "axios": "1.7.7", - "moment-timezone": "^0.5.45", + "moment-timezone": "^0.5.46", "rrule": "2.8.1", "uuid": "^10.0.0" }, From 7fa1ca7ecc30d53bab00f9cc24efe32fa34c7e9a Mon Sep 17 00:00:00 2001 From: sam detweiler Date: Tue, 22 Oct 2024 08:59:23 -0500 Subject: [PATCH 2/7] add handlers for duplicate DTSTART/DTEND in event --- ical.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/ical.js b/ical.js index 33b26d6..d6c0dd1 100644 --- a/ical.js +++ b/ical.js @@ -645,11 +645,23 @@ module.exports = { URL: storeParameter('url'), UID: storeParameter('uid'), LOCATION: storeParameter('location'), - DTSTART(value, parameters, curr, stack) { - curr = dateParameter('start')(value, parameters, curr, stack); - return typeParameter('datetype')(value, parameters, curr); + DTSTART(value, parameters, curr, stack, line) { + // If already defined, this is a duplicate for this event + if (curr.start === undefined) { + curr = dateParameter('start')(value, parameters, curr, stack); + return typeParameter('datetype')(value, parameters, curr); + } + + throw new Error('duplicate DTSTART encountered, line=' + line); + }, + DTEND(value, parameters, curr, stack, line) { + // If already defined, this is a duplicate for this event + if (curr.end === undefined) { + return dateParameter('end')(value, parameters, curr, stack); + } + + throw new Error('duplicate DTEND encountered, line=' + line); }, - DTEND: dateParameter('end'), EXDATE: exdateParameter('exdate'), ' CLASS': storeParameter('class'), // Should there be a space in this property? TRANSP: storeParameter('transparency'), From 0432b3758ab0d56702e1b1f7e21c833d682c103a Mon Sep 17 00:00:00 2001 From: sam detweiler Date: Tue, 22 Oct 2024 09:09:33 -0500 Subject: [PATCH 3/7] update readme for try/catch around async functions --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4b8ed2e..84400a7 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,9 @@ END:VCALENDAR `, function(err, data) { console.log(data); }); ``` +note: If you using the ical.async.xxx functions is a separate async method from your mainline +any thrown errors will be posted to that separate function.. so try/catch must be used around the ical.async.xxx functions + ### autodetect These are the old API examples, which still work and will be converted to the new API automatically. Functions with callbacks provided will also have better performance over the older versions even if they use the old API. From 2f7c3b1c32a2d082d1c332e941605280819dc496 Mon Sep 17 00:00:00 2001 From: sam detweiler Date: Tue, 22 Oct 2024 09:13:39 -0500 Subject: [PATCH 4/7] fix package.json again --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 373364a..9cf593a 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "dependencies": { "axios": "1.7.7", - "moment-timezone": "^0.5.46", + "moment-timezone": "^0.5.45", "rrule": "2.8.1", "uuid": "^10.0.0" }, From d80593494330066f379574b32a5b4d6dd6778413 Mon Sep 17 00:00:00 2001 From: sam detweiler Date: Tue, 22 Oct 2024 11:51:08 -0500 Subject: [PATCH 5/7] fix throw data parm, handled differently in throw message vs old console.log(, parm) --- ical.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ical.js b/ical.js index d6c0dd1..608b8cd 100644 --- a/ical.js +++ b/ical.js @@ -372,7 +372,7 @@ const exdateParameter = function (name) { if (typeof exdate[name].toISOString === 'function') { curr[name][exdate[name].toISOString().slice(0, 10)] = exdate[name]; } else { - throw new TypeError('No toISOString function in exdate[name]', exdate[name]); + throw new TypeError('No toISOString function in exdate[name] = '+ exdate[name]); } } } @@ -548,7 +548,7 @@ module.exports = { if (typeof curr.recurrenceid.toISOString === 'function') { par[curr.uid].recurrences[curr.recurrenceid.toISOString().slice(0, 10)] = recurrenceObject; } else { // Removed issue 56 - throw new TypeError('No toISOString function in curr.recurrenceid', curr.recurrenceid); + throw new TypeError('No toISOString function in curr.recurrenceid ='+ curr.recurrenceid); } } @@ -623,10 +623,10 @@ module.exports = { rule = rule.replace(/\.\d{3}/, ''); } catch (error) { // This should not happen, issue #56 - throw new Error('ERROR when trying to convert to ISOString', error); + throw new Error('ERROR when trying to convert to ISOString '+ error); } } else { - throw new Error('No toISOString function in curr.start', curr.start); + throw new Error('No toISOString function in curr.start '+ curr.start); } } From e544b6fbd7595a49bf5d1ad5427e1b18f3093f09 Mon Sep 17 00:00:00 2001 From: sam detweiler Date: Tue, 22 Oct 2024 14:46:38 -0500 Subject: [PATCH 6/7] fix lint spacing --- ical.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ical.js b/ical.js index 608b8cd..2d088ca 100644 --- a/ical.js +++ b/ical.js @@ -372,7 +372,7 @@ const exdateParameter = function (name) { if (typeof exdate[name].toISOString === 'function') { curr[name][exdate[name].toISOString().slice(0, 10)] = exdate[name]; } else { - throw new TypeError('No toISOString function in exdate[name] = '+ exdate[name]); + throw new TypeError('No toISOString function in exdate[name] = ' + exdate[name]); } } } @@ -548,7 +548,7 @@ module.exports = { if (typeof curr.recurrenceid.toISOString === 'function') { par[curr.uid].recurrences[curr.recurrenceid.toISOString().slice(0, 10)] = recurrenceObject; } else { // Removed issue 56 - throw new TypeError('No toISOString function in curr.recurrenceid ='+ curr.recurrenceid); + throw new TypeError('No toISOString function in curr.recurrenceid =' + curr.recurrenceid); } } @@ -623,10 +623,10 @@ module.exports = { rule = rule.replace(/\.\d{3}/, ''); } catch (error) { // This should not happen, issue #56 - throw new Error('ERROR when trying to convert to ISOString '+ error); + throw new Error('ERROR when trying to convert to ISOString ' + error); } } else { - throw new Error('No toISOString function in curr.start '+ curr.start); + throw new Error('No toISOString function in curr.start ' + curr.start); } } From afee8ed47376c5f464044bab5299e350a16994a4 Mon Sep 17 00:00:00 2001 From: Jens Maus Date: Mon, 28 Oct 2024 15:45:33 +0100 Subject: [PATCH 7/7] integrate coderabbitai suggestion on README.md --- README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 84400a7..97b844d 100644 --- a/README.md +++ b/README.md @@ -137,8 +137,18 @@ END:VCALENDAR `, function(err, data) { console.log(data); }); ``` -note: If you using the ical.async.xxx functions is a separate async method from your mainline -any thrown errors will be posted to that separate function.. so try/catch must be used around the ical.async.xxx functions +Note: When using the `ical.async.*` functions in a separate async context from your main code, +errors will be thrown in that separate context. Therefore, you must wrap these function calls +in try/catch blocks to properly handle any errors. For example: + +```javascript +try { + const events = await ical.async.parseFile('calendar.ics'); + // Process events +} catch (error) { + console.error('Failed to parse calendar:', error); +} +``` ### autodetect These are the old API examples, which still work and will be converted to the new API automatically.