Clean up console logging and fix platform detection issues

- Reduce migration/platform logging verbosity in development mode (~80-90% less noise)
- Fix AbsurdSQL platform check to support 'development' alongside 'web'
- Add missing WebPlatformService methods (isWorker, initSharedArrayBuffer)
- Fix Electron API endpoint resolution to prevent JSON parsing errors
- Prevent circular database logging that caused [DB-PREVENTED-INFO] spam

Console now shows only essential information while preserving all errors/warnings
This commit is contained in:
Matthew Raymer
2025-07-03 06:31:43 +00:00
parent 292aceee75
commit b377667207
8 changed files with 162 additions and 46 deletions

View File

@@ -70,11 +70,13 @@ class AbsurdSqlDatabaseService implements DatabaseService {
return;
}
// **PLATFORM CHECK**: AbsurdSqlDatabaseService should only run on web platform
// **PLATFORM CHECK**: AbsurdSqlDatabaseService should only run on web-based platforms
// This prevents SharedArrayBuffer checks and web-specific initialization on Electron/Capacitor
if (process.env.VITE_PLATFORM !== "web") {
// Allow both 'web' (production) and 'development' (dev server) platforms
const webBasedPlatforms = ["web", "development"];
if (!webBasedPlatforms.includes(process.env.VITE_PLATFORM || "")) {
throw new Error(
`AbsurdSqlDatabaseService is only supported on web platform. Current platform: ${process.env.VITE_PLATFORM}`,
`AbsurdSqlDatabaseService is only supported on web-based platforms (web, development). Current platform: ${process.env.VITE_PLATFORM}`,
);
}
@@ -97,12 +99,16 @@ class AbsurdSqlDatabaseService implements DatabaseService {
// **SHARED ARRAY BUFFER FALLBACK**: Only needed for web platform
// This check handles Safari and other browsers without SharedArrayBuffer support
if (typeof SharedArrayBuffer === "undefined") {
logger.debug("[AbsurdSqlDatabaseService] SharedArrayBuffer not available, using fallback mode");
logger.debug(
"[AbsurdSqlDatabaseService] SharedArrayBuffer not available, using fallback mode",
);
const stream = SQL.FS.open(path, "a+");
await stream.node.contents.readIfFallback();
SQL.FS.close(stream);
} else {
logger.debug("[AbsurdSqlDatabaseService] SharedArrayBuffer available, using optimized mode");
logger.debug(
"[AbsurdSqlDatabaseService] SharedArrayBuffer available, using optimized mode",
);
}
this.db = new SQL.Database(path, { filename: true });

View File

@@ -400,12 +400,17 @@ async function isSchemaAlreadyPresent<T>(
* ```
*/
export async function runMigrations<T>(
sqlExec: (sql: string, params?: unknown[]) => Promise<unknown>,
sqlExec: (sql: string, params?: unknown[]) => Promise<void>,
sqlQuery: (sql: string, params?: unknown[]) => Promise<T>,
extractMigrationNames: (result: T) => Set<string>,
): Promise<void> {
const isDevelopment = process.env.VITE_PLATFORM === "development";
// Use debug level for routine migration messages in development
const migrationLog = isDevelopment ? logger.debug : logger.log;
try {
logger.log("📋 [Migration] Starting migration process...");
migrationLog("📋 [Migration] Starting migration process...");
// Step 1: Create migrations table if it doesn't exist
// Note: We use IF NOT EXISTS here because this is infrastructure, not a business migration
@@ -431,7 +436,7 @@ export async function runMigrations<T>(
return;
}
logger.log(
migrationLog(
`📊 [Migration] Found ${migrations.length} total migrations, ${appliedMigrations.size} already applied`,
);
@@ -458,7 +463,7 @@ export async function runMigrations<T>(
await sqlExec("INSERT INTO migrations (name) VALUES (?)", [
migration.name,
]);
logger.log(
migrationLog(
`✅ [Migration] Marked existing schema as applied: ${migration.name}`,
);
skippedCount++;
@@ -473,7 +478,7 @@ export async function runMigrations<T>(
}
// Apply the migration
logger.log(`🔄 [Migration] Applying migration: ${migration.name}`);
migrationLog(`🔄 [Migration] Applying migration: ${migration.name}`);
try {
// Execute the migration SQL
@@ -496,7 +501,7 @@ export async function runMigrations<T>(
migration.name,
]);
logger.log(`🎉 [Migration] Successfully applied: ${migration.name}`);
migrationLog(`🎉 [Migration] Successfully applied: ${migration.name}`);
appliedCount++;
} catch (error) {
logger.error(`❌ [Migration] Error applying ${migration.name}:`, error);
@@ -512,7 +517,7 @@ export async function runMigrations<T>(
(errorMessage.includes("table") &&
errorMessage.includes("already exists"))
) {
logger.log(
migrationLog(
`⚠️ [Migration] ${migration.name} appears already applied (${errorMessage}). Validating and marking as complete.`,
);
@@ -533,7 +538,7 @@ export async function runMigrations<T>(
await sqlExec("INSERT INTO migrations (name) VALUES (?)", [
migration.name,
]);
logger.log(`✅ [Migration] Marked as applied: ${migration.name}`);
migrationLog(`✅ [Migration] Marked as applied: ${migration.name}`);
appliedCount++;
} catch (insertError) {
// If we can't insert the migration record, log it but don't fail
@@ -569,6 +574,7 @@ export async function runMigrations<T>(
);
}
// Always show completion message
logger.log(
`🎉 [Migration] Migration process complete! Summary: ${appliedCount} applied, ${skippedCount} skipped`,
);

View File

@@ -48,15 +48,21 @@ export class WebPlatformService implements PlatformService {
constructor() {
WebPlatformService.instanceCount++;
// Only warn if multiple instances (which shouldn't happen with singleton)
if (WebPlatformService.instanceCount > 1) {
console.error(
`[WebPlatformService] ERROR: Multiple instances created! Count: ${WebPlatformService.instanceCount}`,
);
} else {
console.log(`[WebPlatformService] Initializing web platform service`);
// Use debug level logging for development mode to reduce console noise
const isDevelopment = process.env.VITE_PLATFORM === "development";
const log = isDevelopment ? logger.debug : logger.log;
log("[WebPlatformService] Initializing web platform service");
// Only initialize SharedArrayBuffer setup for web platforms
if (this.isWorker()) {
log("[WebPlatformService] Skipping initBackend call in worker context");
return;
}
// Initialize shared array buffer for main thread
this.initSharedArrayBuffer();
// Start worker initialization but don't await it in constructor
this.workerInitPromise = this.initializeWorker();
}
@@ -629,4 +635,18 @@ export class WebPlatformService implements PlatformService {
async rotateCamera(): Promise<void> {
throw new Error("Camera rotation not implemented in web platform");
}
/**
* Checks if running in a worker context
*/
private isWorker(): boolean {
return typeof window === "undefined";
}
/**
* Initialize SharedArrayBuffer setup (handled by initBackend in initializeWorker)
*/
private initSharedArrayBuffer(): void {
// SharedArrayBuffer initialization is handled by initBackend call in initializeWorker
}
}