Skip to content

Commit 3859501

Browse files
committed
fix(notion-fetch): improve logging and timeout for skipped content (Phase 1)
Phase 1 of fixing issue #95: Content being skipped during fetch Changes: 1. Add detailed skip reason logging in generateBlocks.ts - Shows specific reason why each page is skipped (cache hit, timestamp, path change, etc.) - Helps diagnose incorrect skip behavior - Includes "should not skip" warnings for potential bugs 2. Enhanced sub-page timeout error logging in fetchNotionData.ts - Display error type and detailed message - Add helpful hints when timeout occurs - Better categorization of failures (timeout vs API error vs permission) 3. Increase sub-page fetch timeout from 10s to 30s - Handles slow Notion API responses better - Reduces false positive timeouts for complex pages - Particularly helpful for pages with large blocks or nested children Benefits: - Immediate diagnostic value for debugging skipped pages - Fewer legitimate pages timing out and being skipped - Clear visibility into incremental sync behavior Related: ISSUE_95_PLAN.md
1 parent b0b9f4b commit 3859501

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

scripts/fetchNotionData.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ export async function sortAndExpandNotionData(
186186
try {
187187
// Add explicit timeout to prevent hanging indefinitely
188188
// GitHub Actions seems to have issues with Notion API calls hanging
189-
const TIMEOUT_MS = 10000; // 10 second timeout
189+
// Increased from 10s to 30s to handle slow Notion API responses,
190+
// particularly for pages with large blocks or many nested children
191+
const TIMEOUT_MS = 30000; // 30 second timeout
190192
const timeoutPromise = new Promise((_resolve, reject) =>
191193
setTimeout(
192194
() =>
@@ -221,9 +223,28 @@ export async function sortAndExpandNotionData(
221223
} catch (pageError) {
222224
// Log the error but don't let it fail the entire batch
223225
// Timeouts and individual page failures should be handled gracefully
226+
const errorMessage =
227+
pageError instanceof Error
228+
? pageError.message
229+
: String(pageError);
230+
const errorType =
231+
pageError instanceof Error
232+
? pageError.constructor.name
233+
: typeof pageError;
234+
const isTimeout = errorMessage.toLowerCase().includes("timeout");
235+
224236
console.warn(
225-
`⚠️ Skipping sub-page ${rel.subId} (parent: "${rel.parentTitle}"): ${pageError.message}`
237+
`⚠️ Skipping sub-page ${rel.subId} (parent: "${rel.parentTitle}")`
226238
);
239+
console.warn(` Error: ${errorMessage}`);
240+
console.warn(` Type: ${errorType}`);
241+
242+
if (isTimeout) {
243+
console.warn(
244+
` 💡 Hint: This page timed out. Consider increasing TIMEOUT_MS in fetchNotionData.ts`
245+
);
246+
}
247+
227248
return null; // Return null for failed pages, filter them out later
228249
}
229250
})

scripts/notion-fetch/generateBlocks.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,29 @@ export async function generateBlocks(
712712

713713
if (!needsProcessing) {
714714
// Page unchanged, skip processing but still count it
715-
console.log(
716-
chalk.gray(` ⏭️ Skipping unchanged page: ${pageTitle}`)
717-
);
715+
// Determine the specific reason for skipping (for diagnostics)
716+
let skipReason: string;
717+
if (syncMode.fullRebuild) {
718+
// This condition can't be reached if !needsProcessing, but for completeness
719+
skipReason = "full rebuild mode";
720+
} else if (!cachedPage) {
721+
skipReason = "not in cache (NEW PAGE - should not skip)";
722+
} else if (hasMissingOutputs(metadataCache, page.id)) {
723+
skipReason = "missing output files (should not skip)";
724+
} else if (!cachedPage.outputPaths?.includes(filePath)) {
725+
skipReason = `path changed from [${cachedPage.outputPaths?.join(", ") || "none"}] to [${filePath}] (should not skip)`;
726+
} else {
727+
const notionTime = new Date(page.last_edited_time).getTime();
728+
const cachedTime = new Date(cachedPage.lastEdited).getTime();
729+
if (notionTime > cachedTime) {
730+
skipReason = `timestamp updated (${page.last_edited_time} > ${cachedPage.lastEdited}) (should not skip)`;
731+
} else {
732+
skipReason = `unchanged since ${cachedPage.lastEdited}`;
733+
}
734+
}
735+
736+
console.log(chalk.gray(` ⏭️ Skipping page: ${pageTitle}`));
737+
console.log(chalk.dim(` Reason: ${skipReason}`));
718738
processedPages++;
719739
progressCallback({ current: processedPages, total: totalPages });
720740
} else if (dryRun) {

0 commit comments

Comments
 (0)