Skip to content

Commit 51f1447

Browse files
fix: Add defensive database validation in RLM system
Prevents 'this.db.exec is not a function' errors by: 1. Validating database instance has required exec() method 2. Testing database connectivity with simple query 3. Providing clear error messages for debugging
1 parent 43426be commit 51f1447

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/cli/commands/skills.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,28 @@ async function initializeSkillContext(): Promise<{
5757
const database = new SQLiteAdapter(projectId, { dbPath });
5858
await database.connect();
5959

60+
// Get raw database for FrameManager
61+
const rawDatabase = database.getRawDatabase();
62+
if (!rawDatabase) {
63+
throw new Error('Failed to get raw database connection');
64+
}
65+
66+
// Validate database has required methods
67+
if (typeof rawDatabase.exec !== 'function') {
68+
throw new Error(`Invalid database instance: missing exec() method. Got: ${typeof rawDatabase.exec}`);
69+
}
70+
71+
// Test database connectivity
72+
try {
73+
rawDatabase.exec('SELECT 1');
74+
} catch (err) {
75+
throw new Error(`Database connection test failed: ${err.message}`);
76+
}
77+
6078
const dualStackManager = new DualStackManager(database, projectId, userId);
6179
const handoffManager = new FrameHandoffManager(dualStackManager);
6280
const contextRetriever = new ContextRetriever(database);
63-
const frameManager = new FrameManager(database);
81+
const frameManager = new FrameManager(rawDatabase);
6482
const taskStore = new LinearTaskManager();
6583

6684
const context: SkillContext = {

src/core/context/frame-manager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ export class FrameManager {
192192
});
193193

194194
try {
195+
// Check if database is properly initialized
196+
if (!this.db || typeof this.db.exec !== 'function') {
197+
throw new Error('Database not properly initialized. Expected SQLite Database instance with exec() method.');
198+
}
199+
195200
// Enhanced frames table matching architecture
196201
this.db.exec(`
197202
CREATE TABLE IF NOT EXISTS frames (

0 commit comments

Comments
 (0)