Skip to content

Fix: Database initialization error preventing app launch in v0.3.0#191

Open
jordan-BAIC wants to merge 2 commits into
mainfrom
investigate-crystal-issue-189
Open

Fix: Database initialization error preventing app launch in v0.3.0#191
jordan-BAIC wants to merge 2 commits into
mainfrom
investigate-crystal-issue-189

Conversation

@jordan-BAIC

Copy link
Copy Markdown
Collaborator

Summary

Fixes the critical issue where Crystal fails to launch after upgrading to v0.3.0, with the main window not appearing despite the app starting.

Problem

Users reported that after updating to v0.3.0, the application would launch but the main window wouldn't appear. The root cause was a database migration failure with the error:

TypeError: Cannot read properties of undefined (reading 'getDefaultModel')

Root Cause

During database migrations, the code attempted to dynamically require() a configManager instance that didn't exist. The services/configManager module only exported the ConfigManager class, not an instance, causing the migration to fail and preventing the app from launching properly.

Solution

  1. Pass configManager to DatabaseService: Modified the DatabaseService constructor to accept an optional configManager parameter, eliminating the need for dynamic requires during migrations
  2. Created service registry: Implemented a serviceRegistry pattern to manage singleton service instances across the application
  3. Updated validation functions: Made databaseService parameter optional so functions can either receive it directly or fetch from registry
  4. Removed problematic singleton: Deleted the uninitialized services/database.ts singleton that was causing confusion
  5. Updated all references: Changed all code to use proper service access patterns

Testing

  • ✅ TypeScript compilation passes
  • ✅ Database migrations now run successfully with configManager access
  • ✅ Claude panel settings creation works with default model from config

Impact

This fix resolves the app launch failure that affected all users upgrading to v0.3.0.

Fixes #189

🤖 Generated with Claude Code

…0.3.0

The app failed to launch after upgrading to v0.3.0 due to database migrations
attempting to access a non-existent configManager instance via require().

Changes:
- Pass configManager to DatabaseService constructor instead of using require()
- Create serviceRegistry for managing singleton service instances
- Update sessionValidation functions to optionally accept databaseService parameter
- Remove problematic singleton database.ts that was never initialized
- Update all references to use getDatabaseService() from registry

This fixes the "Cannot read properties of undefined (reading 'getDefaultModel')"
error that prevented the main window from appearing after app launch.

Fixes #189

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Launch failure (no window) in v0.3.0

1 participant