From 2e8c264cecd14ad36aa1711466e60af8e31cc035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Pluta?= Date: Thu, 30 Jan 2025 19:37:16 +0100 Subject: [PATCH] Put some logging and skip parsing issues for failing lines --- src/backend/index.ts | 1 + src/loader/index.ts | 16 +++++++++++++--- src/runner/index.ts | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/backend/index.ts b/src/backend/index.ts index 4ea5b5a..c51959d 100644 --- a/src/backend/index.ts +++ b/src/backend/index.ts @@ -17,6 +17,7 @@ export async function remind(config: Config, db: NotificationDatabase) { for (const notification of notifications) { for (const backend of backends) { + console.info(`Dispatching a notification: [${notification.text}]`) backend.remind(config, notification); await snooze(1500); } diff --git a/src/loader/index.ts b/src/loader/index.ts index 3278552..8eec5f3 100644 --- a/src/loader/index.ts +++ b/src/loader/index.ts @@ -70,10 +70,20 @@ async function readTasksFromFile(path: string): Promise { const list: Task[] = []; for await (const line of lines) { - const task = parseTask(line); + try { + const task = parseTask(line); - if(task) { - list.push(task); + if(task) { + list.push(task); + } + } catch(e: any) { + console.warn(`Parsing error in file '${path}', for line:`); + console.warn(line); + if(e.location) { + console.warn(' '.repeat(e.location.start.column + 2) + "^" + '~'.repeat(e.location.end.column - e.location.start.column - 1) + "^") + } + console.warn(e.message); + console.warn("This line will be ignored. Please check the source and adjust it accordingly."); } } diff --git a/src/runner/index.ts b/src/runner/index.ts index 4a02a4e..af3eddc 100644 --- a/src/runner/index.ts +++ b/src/runner/index.ts @@ -21,6 +21,7 @@ export async function test(config: Config) { export async function scan(config: Config) { const tasks = await loadTasks(config.sources, config.query); + console.info(tasks.length > 0 ? `Scheduled reminders for ${tasks.length} task(s)` : `No tasks to remind`) dumpDatabase(config.databaseFile, tasks, config.mapper); }