Browse Source

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
pull/134/head
Matthew Raymer 1 week ago
parent
commit
710cc1683c
  1. 23
      electron/src/rt/sqlite-init.ts

23
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);

Loading…
Cancel
Save