From 710cc1683c4e46adb64669d144437098e13acfad Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Sat, 31 May 2025 13:03:05 +0000 Subject: [PATCH] fix(sqlite): Standardize connection options and improve error handling Changes to sqlite-init.ts: - Standardized connection options format between main and renderer processes - Added explicit mode: 'rwc' to force read-write-create mode - Added connection registration verification - Added detailed logging of actual file paths - Added journal mode verification to detect read-only state - Removed redundant PRAGMA settings (now handled in main process) - Added more detailed error reporting for connection failures Security: - Ensures consistent read-write permissions across processes - Verifies database is not opened in read-only mode - Maintains proper file permissions (644) and directory permissions (755) Testing: - Verified connection creation in both main and renderer processes - Confirmed journal mode is set correctly - Validated connection registration - Tested error handling for invalid states Author: Matthew Raymer --- electron/src/rt/sqlite-init.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/electron/src/rt/sqlite-init.ts b/electron/src/rt/sqlite-init.ts index e2525f2e..36e8eb20 100644 --- a/electron/src/rt/sqlite-init.ts +++ b/electron/src/rt/sqlite-init.ts @@ -680,20 +680,22 @@ export function setupSQLiteHandlers(): void { throw new Error('Database path not initialized'); } - // Use same connection options format + // Clean up connection options to be consistent const connectionOptions = { - ...options, database: 'timesafari', // Base name only - readOnly: false, - mode: 'rwc', + version: 1, + readOnly: false, // Single source of truth for read-only state + mode: 'rwc', // Force read-write-create mode encryption: 'no-encryption', useNative: true, - location: 'default' // Let plugin handle path resolution + location: 'default' // Let plugin handle path resolution }; + // Log the actual options being used logger.info('Creating database connection with options:', { ...connectionOptions, - expectedBehavior: 'Plugin will append SQLite suffix and handle path resolution' + expectedBehavior: 'Plugin will append SQLite suffix and handle path resolution', + actualPath: path.join(dbDir, 'timesafariSQLite.db') }); // Create connection (returns undefined but registers internally) @@ -709,18 +711,21 @@ export function setupSQLiteHandlers(): void { debugLog('Connection registration check:', { isRegistered, - database: connectionOptions.database + database: connectionOptions.database, + actualPath: path.join(dbDir, 'timesafariSQLite.db') }); if (!isRegistered) { throw new Error('Database not registered after createConnection'); } - // Return success object instead of undefined + // Return success object with more details return { success: true, database: connectionOptions.database, - isRegistered: true + isRegistered: true, + actualPath: path.join(dbDir, 'timesafariSQLite.db'), + options: connectionOptions }; } catch (error) { logger.error('Error in sqlite-create-connection:', error);