From 2ab296ed1d0d12309df895b1797ea8b29d5f94b7 Mon Sep 17 00:00:00 2001 From: Trang Doan Date: Mon, 2 Mar 2026 23:41:06 -0500 Subject: [PATCH 1/2] fix(obsidian): remove unnecessary console logging statements (PG-G2) Remove console.log, console.warn, and console.debug statements from production code across 8 files. Retained console.error for legitimate error handling. Co-Authored-By: Claude Opus 4.6 --- .../src/components/canvas/TldrawView.tsx | 12 ++-- .../canvas/utils/relationJsonUtils.ts | 15 ++--- apps/obsidian/src/services/QueryEngine.ts | 23 +++----- apps/obsidian/src/utils/fileChangeListener.ts | 32 +++++------ apps/obsidian/src/utils/importNodes.ts | 16 +----- apps/obsidian/src/utils/publishNode.ts | 6 -- .../src/utils/syncDgNodesToSupabase.ts | 55 ------------------- apps/obsidian/src/utils/templates.ts | 3 - 8 files changed, 31 insertions(+), 131 deletions(-) diff --git a/apps/obsidian/src/components/canvas/TldrawView.tsx b/apps/obsidian/src/components/canvas/TldrawView.tsx index f96c3efd9..4bec8bc97 100644 --- a/apps/obsidian/src/components/canvas/TldrawView.tsx +++ b/apps/obsidian/src/components/canvas/TldrawView.tsx @@ -81,8 +81,8 @@ export class TldrawView extends TextFileView { ); const store = this.createStore(fileData, assetStore); + // [PG-G2] Removed console.warn if (!store) { - console.warn("No tldraw data found in file"); return; } @@ -99,14 +99,14 @@ export class TldrawView extends TextFileView { /```json !!!_START_OF_TLDRAW_DG_DATA__DO_NOT_CHANGE_THIS_PHRASE_!!!([\s\S]*?)!!!_END_OF_TLDRAW_DG_DATA__DO_NOT_CHANGE_THIS_PHRASE_!!!\n```/, ); + // [PG-G2] Removed console.warn if (!match?.[1]) { - console.warn("No tldraw data found in file"); return; } const data = JSON.parse(match[1]) as TLData; + // [PG-G2] Removed console.warn if (!data.raw) { - console.warn("Invalid tldraw data format - missing raw field"); return; } if (data.meta?.uuid) { @@ -115,8 +115,8 @@ export class TldrawView extends TextFileView { this.canvasUuid = window.crypto.randomUUID(); } + // [PG-G2] Removed console.warn if (!this.file) { - console.warn("TldrawView not initialized: missing file"); return; } @@ -151,8 +151,8 @@ export class TldrawView extends TextFileView { if (!this.canvasUuid) throw new Error("TldrawView not initialized: missing canvas UUID"); + // [PG-G2] Removed console.warn if (!this.assetStore) { - console.warn("Asset store is not set"); return; } @@ -254,4 +254,4 @@ export class TldrawView extends TextFileView { this.assetStore = null; } } -} \ No newline at end of file +} diff --git a/apps/obsidian/src/components/canvas/utils/relationJsonUtils.ts b/apps/obsidian/src/components/canvas/utils/relationJsonUtils.ts index 7e547c57a..659b48793 100644 --- a/apps/obsidian/src/components/canvas/utils/relationJsonUtils.ts +++ b/apps/obsidian/src/components/canvas/utils/relationJsonUtils.ts @@ -27,13 +27,10 @@ export const addRelationToRelationsJson = async ({ const destId = await getNodeInstanceIdForFile(plugin, targetFile); if (!sourceId || !destId) { + // [PG-G2] Removed console.warn const missing: string[] = []; if (!sourceId) missing.push(`source (${sourceFile.basename})`); if (!destId) missing.push(`target (${targetFile.basename})`); - console.warn( - "Could not resolve nodeInstanceIds for relation files:", - missing.join(", "), - ); new Notice( "Could not create relation: one or both files are not discourse nodes or metadata is not ready.", 3000, @@ -73,10 +70,8 @@ export const addRelationIfRequested = async ( getNodeTypeIdForFile(plugin, createdOrSelectedFile), getNodeTypeIdForFile(plugin, relationshipTargetFile), ]); + // [PG-G2] Removed console.warn if (!typeA || !typeB) { - console.warn( - "addRelationIfRequested: could not resolve node types for one or both files", - ); return; } @@ -91,10 +86,8 @@ export const addRelationIfRequested = async ( } else if (relation.sourceId === relation.destinationId) { sourceFile = createdOrSelectedFile; targetFile = relationshipTargetFile; + // [PG-G2] Removed console.warn } else { - console.warn( - "addRelationIfRequested: file node types do not match relation definition", - ); return; } @@ -104,4 +97,4 @@ export const addRelationIfRequested = async ( targetFile, relationTypeId: relation.relationshipTypeId, }); -}; \ No newline at end of file +}; diff --git a/apps/obsidian/src/services/QueryEngine.ts b/apps/obsidian/src/services/QueryEngine.ts index 25595be1e..27bb49a4f 100644 --- a/apps/obsidian/src/services/QueryEngine.ts +++ b/apps/obsidian/src/services/QueryEngine.ts @@ -50,9 +50,7 @@ export class QueryEngine { return []; } if (!this.dc) { - console.warn( - "Datacore API not available. Search functionality is not available.", - ); + // [PG-G2] Removed console.warn return []; } @@ -125,9 +123,7 @@ export class QueryEngine { return []; } if (!this.dc) { - console.warn( - "Datacore API not available. Search functionality is not available.", - ); + // [PG-G2] Removed console.warn return []; } @@ -244,10 +240,8 @@ export class QueryEngine { ): Promise { const candidates: BulkImportCandidate[] = []; + // [PG-G2] Removed console.warn - silently fall back to vault iteration if (!this.dc) { - console.warn( - "Datacore API not available. Falling back to vault iteration.", - ); return this.fallbackScanVault(patterns, validNodeTypes); } @@ -289,10 +283,8 @@ export class QueryEngine { (nt) => nt.id === pattern.nodeTypeId, ); + // [PG-G2] Removed console.warn - skip patterns without matching node types if (!matchedNodeType) { - console.warn( - `No matching node type found for pattern with nodeTypeId: ${pattern.nodeTypeId}`, - ); continue; } @@ -347,8 +339,9 @@ export class QueryEngine { } } } + // [PG-G2] Removed console.warn - silently handle DataCore query errors } catch (error) { - console.warn("Error querying DataCore for imported file:", error); + // Silently fail and continue } } @@ -402,10 +395,8 @@ export class QueryEngine { (nt) => nt.id === pattern.nodeTypeId, ); + // [PG-G2] Removed console.warn - skip patterns without matching node types if (!matchedNodeType) { - console.warn( - `No matching node type found for pattern with nodeTypeId: ${pattern.nodeTypeId}`, - ); continue; } diff --git a/apps/obsidian/src/utils/fileChangeListener.ts b/apps/obsidian/src/utils/fileChangeListener.ts index 1abf232ab..c83954e1b 100644 --- a/apps/obsidian/src/utils/fileChangeListener.ts +++ b/apps/obsidian/src/utils/fileChangeListener.ts @@ -74,7 +74,7 @@ export class FileChangeListener { }; this.plugin.app.metadataCache.on("changed", this.metadataChangeCallback); - console.debug("FileChangeListener initialized"); + // [PG-G2] Removed console.debug } /** @@ -134,7 +134,7 @@ export class FileChangeListener { return; } - console.log(`File modified: ${file.path}`); + // [PG-G2] Removed console.log this.queueChange(file.path, "content"); } @@ -146,7 +146,7 @@ export class FileChangeListener { return; } - console.log(`File deleted: ${file.path}`); + // [PG-G2] Removed console.log this.hasPendingOrphanCleanup = true; this.resetDebounceTimer(); } @@ -159,7 +159,7 @@ export class FileChangeListener { return; } - console.log(`File renamed: ${oldPath} -> ${file.path}`); + // [PG-G2] Removed console.log this.queueChange(file.path, "title", oldPath); } @@ -186,9 +186,7 @@ export class FileChangeListener { // In the future, this can detect specific relation changes const cache = this.plugin.app.metadataCache.getFileCache(file); if (cache?.frontmatter) { - console.debug( - `Metadata changed for ${file.path} (relation metadata placeholder)`, - ); + // [PG-G2] Removed console.debug } } @@ -235,7 +233,7 @@ export class FileChangeListener { */ private async processQueue(): Promise { if (this.isProcessing) { - console.debug("Sync already in progress, skipping"); + // [PG-G2] Removed console.debug return; } @@ -283,30 +281,26 @@ export class FileChangeListener { } } + // [PG-G2] Removed console.debug if (processedFiles.length > 0) { - console.debug( - `Successfully processed ${processedFiles.length} file(s):`, - processedFiles, - ); + // Successfully processed files } + // [PG-G2] Removed console.warn if (failedFiles.length > 0) { - console.warn( - `Failed to process ${failedFiles.length} file(s), will retry on next change:`, - failedFiles, - ); + // Failed files will retry on next change } if (this.hasPendingOrphanCleanup) { const deletedCount = await cleanupOrphanedNodes(this.plugin); if (deletedCount > 0) { - console.debug(`Deleted ${deletedCount} orphaned node(s)`); + // [PG-G2] Removed console.debug } this.hasPendingOrphanCleanup = false; } if (processedFiles.length > 0 || failedFiles.length === 0) { - console.debug("Sync queue processed"); + // [PG-G2] Removed console.debug } } catch (error) { console.error("Error processing sync queue:", error); @@ -342,6 +336,6 @@ export class FileChangeListener { this.pendingCreates.clear(); this.isProcessing = false; - console.debug("FileChangeListener cleaned up"); + // [PG-G2] Removed console.debug } } diff --git a/apps/obsidian/src/utils/importNodes.ts b/apps/obsidian/src/utils/importNodes.ts index b83c3620f..f30b20661 100644 --- a/apps/obsidian/src/utils/importNodes.ts +++ b/apps/obsidian/src/utils/importNodes.ts @@ -354,12 +354,6 @@ const fetchNodeContentForImport = async ({ full.created == null || full.last_modified == null ) { - if (!direct?.text) { - console.warn(`No direct variant found for node ${nodeInstanceId}`); - } - if (!full?.text) { - console.warn(`No full variant found for node ${nodeInstanceId}`); - } return null; } @@ -458,12 +452,10 @@ const downloadFileFromStorage = async ({ .download(filehash); if (error) { - console.warn(`Error downloading file ${filehash}:`, error); return null; } if (!data) { - console.warn(`No data returned for file ${filehash}`); return null; } @@ -858,7 +850,6 @@ const importAssetsForNode = async ({ if (!fileContent) { errors.push(`Failed to download file: ${filepath}`); - console.warn(`Failed to download file ${filepath} (hash: ${filehash})`); continue; } @@ -898,7 +889,6 @@ const importAssetsForNode = async ({ // Track path mapping (raw + normalized key so updateMarkdownAssetLinks can lookup by link text) setPathMapping(filepath, targetPath); - console.log(`Imported asset: ${filepath} -> ${targetPath}`); } catch (error) { const errorMsg = `Error importing asset ${fileRef.filepath}: ${error}`; errors.push(errorMsg); @@ -1173,7 +1163,6 @@ export const importSelectedNodes = async ({ const importFolderPath = `import/${sanitizeFileName(spaceName)}`; const spaceUri = spaceUris.get(spaceId); if (!spaceUri) { - console.warn(`Missing URI for space ${spaceId}`); for (const _node of nodes) { failedCount++; processedCount++; @@ -1304,10 +1293,7 @@ export const importSelectedNodes = async ({ // Log asset import errors if any if (assetImportResult.errors.length > 0) { - console.warn( - `Some assets failed to import for node ${node.nodeInstanceId}:`, - assetImportResult.errors, - ); + // Errors are tracked in assetImportResult } // If title changed and file exists, rename it to match the new title diff --git a/apps/obsidian/src/utils/publishNode.ts b/apps/obsidian/src/utils/publishNode.ts index ca6ac8f09..98a050305 100644 --- a/apps/obsidian/src/utils/publishNode.ts +++ b/apps/obsidian/src/utils/publishNode.ts @@ -41,9 +41,6 @@ const publishSchema = async ({ } if (!schemaResponse.data) { - console.warn( - `Schema with nodeTypeId ${nodeTypeId} not found in space ${spaceId}`, - ); return; // Schema doesn't exist, skip publishing } @@ -298,9 +295,6 @@ export const publishNodeToGroup = async ({ link, file.path, ); - if (attachment === null) { - console.warn("Could not find file for " + link); - } return attachment; }) .filter((a) => !!a); diff --git a/apps/obsidian/src/utils/syncDgNodesToSupabase.ts b/apps/obsidian/src/utils/syncDgNodesToSupabase.ts index d3a8a6e3a..c55299f5a 100644 --- a/apps/obsidian/src/utils/syncDgNodesToSupabase.ts +++ b/apps/obsidian/src/utils/syncDgNodesToSupabase.ts @@ -314,33 +314,6 @@ const detectNodeChanges = ( return changeTypes; }; -const logNodeChanges = ({ - node, - changeTypes, - existingTitle, - lastSyncTime, -}: { - node: DiscourseNodeInVault; - changeTypes: ChangeType[]; - existingTitle: string | undefined; - lastSyncTime: Date; -}): void => { - const currentFilename = node.file.basename; - const fileModifiedTime = new Date(node.file.stat.mtime); - - if (changeTypes.includes("title")) { - console.log( - `Title changed for ${node.nodeInstanceId}: "${existingTitle}" -> "${currentFilename}"`, - ); - } - - if (changeTypes.includes("content")) { - console.log( - `Content changed for ${node.nodeInstanceId} (filename: "${currentFilename}") - file mtime: ${fileModifiedTime.toISOString()}, lastSyncTime: ${lastSyncTime.toISOString()}`, - ); - } -}; - const buildChangedNodesFromNodes = async ({ nodes, supabaseClient, @@ -382,13 +355,6 @@ const buildChangedNodesFromNodes = async ({ continue; } - logNodeChanges({ - node, - changeTypes: finalChangeTypes, - existingTitle, - lastSyncTime, - }); - changedNodes.push({ file: node.file, frontmatter: node.frontmatter, @@ -409,19 +375,15 @@ export const syncAllNodesAndRelations = async ( relationsOnly?: boolean, ): Promise => { try { - console.debug("Starting syncAllNodesAndRelations"); - const context = supabaseContext ?? (await getSupabaseContext(plugin)); if (!context) { throw new Error("Could not create Supabase context"); } const supabaseClient = await getLoggedInClient(plugin); - console.log("supabaseClient", supabaseClient); if (!supabaseClient) { throw new Error("Could not log in to Supabase client"); } - console.debug("Supabase client:", supabaseClient); const allNodes = await collectDiscourseNodesFromVault(plugin); @@ -432,10 +394,6 @@ export const syncAllNodesAndRelations = async ( supabaseClient, context, }); - - console.log("changedNodeInstances", changedNodeInstances); - console.debug(`Found ${changedNodeInstances.length} nodes to sync`); - const accountLocalId = plugin.settings.accountLocalId; if (!accountLocalId) { throw new Error("accountLocalId not found in plugin settings"); @@ -460,8 +418,6 @@ export const syncAllNodesAndRelations = async ( // When synced nodes are already published, ensure non-text assets are in storage. await syncPublishedNodesAssets(plugin, changedNodeInstances); - - console.debug("Sync completed successfully"); } catch (error) { console.error("syncAllNodesAndRelations: Process failed:", error); throw error; @@ -695,7 +651,6 @@ const collectDiscourseNodesFromPaths = async ( for (const filePath of filePaths) { const file = plugin.app.vault.getAbstractFileByPath(filePath); if (!(file instanceof TFile)) { - console.debug(`File not found or not a TFile: ${filePath}`); continue; } @@ -709,12 +664,10 @@ const collectDiscourseNodesFromPaths = async ( // Not a discourse node if (!frontmatter?.nodeTypeId) { - console.debug(`File is not a DG node: ${filePath}`); continue; } if (frontmatter.importedFromRid) { - console.debug(`Skipping imported file: ${filePath}`); continue; } @@ -767,12 +720,7 @@ export const syncDiscourseNodeChanges = async ( try { const filePaths = Array.from(changeTypesByPath.keys()); - console.debug( - `Syncing ${filePaths.length} file change(s) with explicit types`, - ); - if (filePaths.length === 0) { - console.debug("No files to sync"); return; } @@ -792,7 +740,6 @@ export const syncDiscourseNodeChanges = async ( ); if (dgNodesInVault.length === 0) { - console.debug("No DG nodes found in specified files"); return; } @@ -815,8 +762,6 @@ export const syncDiscourseNodeChanges = async ( context, accountLocalId, }); - - console.debug(`Successfully synced ${changedNodes.length} node(s)`); } catch (error) { console.error("syncDiscourseNodeChanges: Process failed:", error); throw error; diff --git a/apps/obsidian/src/utils/templates.ts b/apps/obsidian/src/utils/templates.ts index 2b0895fc9..6805c0e33 100644 --- a/apps/obsidian/src/utils/templates.ts +++ b/apps/obsidian/src/utils/templates.ts @@ -106,12 +106,10 @@ export const applyTemplate = async ({ const { isEnabled, folderPath } = getTemplatePluginInfo(app); if (!isEnabled) { - console.warn("Templates plugin is not enabled"); return false; } if (!folderPath) { - console.warn("Template folder is not configured"); return false; } @@ -119,7 +117,6 @@ export const applyTemplate = async ({ const templateFile = app.vault.getAbstractFileByPath(templateFilePath); if (!templateFile || !(templateFile instanceof TFile)) { - console.warn(`Template file not found: ${templateFilePath}`); return false; } From e425f532a41d57d0f33ccdd2bc8d4a450921f13a Mon Sep 17 00:00:00 2001 From: Trang Doan Date: Tue, 3 Mar 2026 14:58:00 -0500 Subject: [PATCH 2/2] remove comments --- apps/obsidian/src/components/canvas/TldrawView.tsx | 5 ----- apps/obsidian/src/services/QueryEngine.ts | 6 ------ 2 files changed, 11 deletions(-) diff --git a/apps/obsidian/src/components/canvas/TldrawView.tsx b/apps/obsidian/src/components/canvas/TldrawView.tsx index 4bec8bc97..480cc7574 100644 --- a/apps/obsidian/src/components/canvas/TldrawView.tsx +++ b/apps/obsidian/src/components/canvas/TldrawView.tsx @@ -81,7 +81,6 @@ export class TldrawView extends TextFileView { ); const store = this.createStore(fileData, assetStore); - // [PG-G2] Removed console.warn if (!store) { return; } @@ -99,13 +98,11 @@ export class TldrawView extends TextFileView { /```json !!!_START_OF_TLDRAW_DG_DATA__DO_NOT_CHANGE_THIS_PHRASE_!!!([\s\S]*?)!!!_END_OF_TLDRAW_DG_DATA__DO_NOT_CHANGE_THIS_PHRASE_!!!\n```/, ); - // [PG-G2] Removed console.warn if (!match?.[1]) { return; } const data = JSON.parse(match[1]) as TLData; - // [PG-G2] Removed console.warn if (!data.raw) { return; } @@ -115,7 +112,6 @@ export class TldrawView extends TextFileView { this.canvasUuid = window.crypto.randomUUID(); } - // [PG-G2] Removed console.warn if (!this.file) { return; } @@ -151,7 +147,6 @@ export class TldrawView extends TextFileView { if (!this.canvasUuid) throw new Error("TldrawView not initialized: missing canvas UUID"); - // [PG-G2] Removed console.warn if (!this.assetStore) { return; } diff --git a/apps/obsidian/src/services/QueryEngine.ts b/apps/obsidian/src/services/QueryEngine.ts index 27bb49a4f..2a70fd15e 100644 --- a/apps/obsidian/src/services/QueryEngine.ts +++ b/apps/obsidian/src/services/QueryEngine.ts @@ -50,7 +50,6 @@ export class QueryEngine { return []; } if (!this.dc) { - // [PG-G2] Removed console.warn return []; } @@ -123,7 +122,6 @@ export class QueryEngine { return []; } if (!this.dc) { - // [PG-G2] Removed console.warn return []; } @@ -240,7 +238,6 @@ export class QueryEngine { ): Promise { const candidates: BulkImportCandidate[] = []; - // [PG-G2] Removed console.warn - silently fall back to vault iteration if (!this.dc) { return this.fallbackScanVault(patterns, validNodeTypes); } @@ -283,7 +280,6 @@ export class QueryEngine { (nt) => nt.id === pattern.nodeTypeId, ); - // [PG-G2] Removed console.warn - skip patterns without matching node types if (!matchedNodeType) { continue; } @@ -339,7 +335,6 @@ export class QueryEngine { } } } - // [PG-G2] Removed console.warn - silently handle DataCore query errors } catch (error) { // Silently fail and continue } @@ -395,7 +390,6 @@ export class QueryEngine { (nt) => nt.id === pattern.nodeTypeId, ); - // [PG-G2] Removed console.warn - skip patterns without matching node types if (!matchedNodeType) { continue; }