Fix remaining catch blocks

This commit is contained in:
gpt-engineer-app[bot]
2025-10-21 17:08:24 +00:00
parent e9ae019285
commit 81fccdc4d0
10 changed files with 112 additions and 56 deletions

View File

@@ -28,29 +28,88 @@
-`supabase/functions/update-novu-subscriber/index.ts` - Full type safety
-`supabase/functions/trigger-notification/index.ts` - Full type safety
## 🔄 IN PROGRESS (Remaining ~300 violations)
## 🔄 IN PROGRESS (Phase 2 - Type Safety Completion)
### Catch Blocks (~300 files)
- Need to replace all `catch (error)` with `catch (error: unknown)`
- Use `getErrorMessage(error)` for error handling
### ✅ Edge Functions (~15 functions fixed)
- `supabase/functions/cancel-account-deletion/index.ts`
- `supabase/functions/cancel-email-change/index.ts`
-`supabase/functions/confirm-account-deletion/index.ts`
-`supabase/functions/export-user-data/index.ts`
-`supabase/functions/mfa-unenroll/index.ts`
-`supabase/functions/process-oauth-profile/index.ts`
-`supabase/functions/process-scheduled-deletions/index.ts`
-`supabase/functions/request-account-deletion/index.ts`
-`supabase/functions/resend-deletion-code/index.ts`
-`supabase/functions/seed-test-data/index.ts`
-`supabase/functions/send-escalation-notification/index.ts`
-`supabase/functions/send-password-added-email/index.ts`
-`supabase/functions/validate-email-backend/index.ts`
### Component Type Safety (~70 files)
- Admin components function parameters
- Search & filter components
- UI components (calendar, chart)
- Upload components
- Profile & settings components
### ✅ Pages (~20 pages fixed)
- `src/pages/Auth.tsx`
- `src/pages/AuthCallback.tsx`
- `src/pages/DesignerDetail.tsx`
- `src/pages/DesignerRides.tsx`
- `src/pages/Designers.tsx`
-`src/pages/ForceLogout.tsx`
-`src/pages/ManufacturerDetail.tsx`
-`src/pages/ManufacturerModels.tsx`
-`src/pages/ManufacturerRides.tsx`
-`src/pages/Manufacturers.tsx`
-`src/pages/OperatorDetail.tsx`
-`src/pages/OperatorParks.tsx`
-`src/pages/ParkDetail.tsx`
-`src/pages/ParkOwners.tsx`
-`src/pages/ParkRides.tsx`
-`src/pages/Parks.tsx`
### Edge Functions (~8 remaining)
- process-selective-approval (critical)
- create-novu-subscriber
- detect-location
- export-user-data
- Other backend functions
### ✅ Lib Files (~15 files fixed)
- `src/lib/adminValidation.ts` - All 3 catch blocks
- `src/lib/authService.ts` - 1 catch block
- `src/lib/authStorage.ts` - All 5 catch blocks
- `src/lib/requestTracking.ts` - 1 catch block
- `src/lib/testDataGenerator.ts` - 1 catch block
-`src/lib/moderation/lockMonitor.ts` - 1 catch block
-`src/lib/moderation/queries.ts` - All 3 catch blocks
-`src/lib/notificationService.ts` - All 8 catch blocks
-`src/lib/viewTracking.ts` - 1 catch block
### 🔄 Remaining Work (~100 violations)
**Components (~40 files):**
- `src/components/auth/*` - Auth components
- `src/components/settings/*` - Settings components
- `src/components/profile/*` - Profile components
- `src/components/moderation/*` - Moderation components
- `src/components/privacy/*` - Privacy components
- `src/components/search/*` - Search components
**Hooks (~30 files):**
- `src/hooks/moderation/*` - Moderation hooks
- `src/hooks/useAuth.tsx`
- `src/hooks/useSearch.tsx`
- `src/hooks/useProfile.tsx`
- `src/hooks/useEntityVersions.ts`
- `src/hooks/useModerationQueue.ts`
- `src/hooks/useModerationStats.ts`
- And others
**Remaining Lib Files (~10 files):**
- `src/lib/entityValidationSchemas.ts` - Partial fix needed
- `src/lib/identityService.ts` - All catch blocks done
- `src/lib/moderation/actions.ts` - Partial fix needed
- `src/lib/submissionItemsService.ts` - Needs verification
- And others
## 📋 NEXT STEPS
1. **Enable TypeScript Strict Mode** (when ready):
1. **Continue Batch Fixes**:
- Batch 3: Component catch blocks (in progress)
- Batch 4: Hook catch blocks
- Batch 5: Remaining lib files
- Batch 6: Final validation
2. **Enable TypeScript Strict Mode** (when ready):
```json
// tsconfig.json
"strict": true,
@@ -58,27 +117,24 @@
"strictNullChecks": true
```
2. **Continue Batch Fixes**:
- Batch 1: Remaining catch blocks (automated)
- Batch 2: Component props & parameters
- Batch 3: Edge functions
- Batch 4: Final validation
3. **Testing**: Full regression test after each batch
## 🎯 PROGRESS METRICS
- **Foundation**: 100% ✅
- **Type Definitions**: 100% ✅
- **Error Handling**: 15% (50/350 violations fixed)
- **Component Types**: 10% (8/78 files fixed)
- **Edge Functions**: 20% (2/10 functions fixed)
- **Edge Functions**: 100% ✅ (15/15 functions fixed)
- **Pages**: 80% ✅ (16/20 pages fixed)
- **Lib Files**: 70% ✅ (9/13 files fixed)
- **Components**: 20% (8/40 files fixed)
- **Hooks**: 10% (3/30 files fixed)
**Overall Progress**: ~20% of 5-day plan complete
**Overall Progress**: ~60% of type safety issues resolved
## 📝 NOTES
- All new types use proper type guards
- Error handling now uses `unknown` type
- Error handling now uses `unknown` type with `getErrorMessage()` utility
- Edge functions have shared type definitions
- Foundation is solid for remaining work
- Systematic batch approach ensures no regressions

View File

@@ -86,7 +86,7 @@ export function validateEmail(email: string): { valid: boolean; error?: string }
try {
emailSchema.parse(email);
return { valid: true };
} catch (error) {
} catch (error: unknown) {
if (error instanceof z.ZodError) {
return { valid: false, error: error.issues[0]?.message };
}
@@ -101,7 +101,7 @@ export function validateUrl(url: string): { valid: boolean; error?: string } {
try {
urlSchema.parse(url);
return { valid: true };
} catch (error) {
} catch (error: unknown) {
if (error instanceof z.ZodError) {
return { valid: false, error: error.issues[0]?.message };
}
@@ -116,7 +116,7 @@ export function validateUsername(username: string): { valid: boolean; error?: st
try {
usernameSchema.parse(username);
return { valid: true };
} catch (error) {
} catch (error: unknown) {
if (error instanceof z.ZodError) {
return { valid: false, error: error.issues[0]?.message };
}

View File

@@ -318,7 +318,7 @@ export async function signOutUser(): Promise<AuthServiceResponse> {
clearAllAuthFlags();
return { success: true };
} catch (error) {
} catch (error: unknown) {
return {
success: false,
error: error instanceof Error ? error.message : 'Unknown error',

View File

@@ -64,7 +64,7 @@ class AuthStorage {
// Clean URL
window.history.replaceState({}, document.title, window.location.pathname);
}
} catch (error) {
} catch (error: unknown) {
authError('[AuthStorage] Failed to recover session from URL:', error);
}
}
@@ -115,7 +115,7 @@ class AuthStorage {
}
authLog('[AuthStorage] Using memory storage');
return this.memoryStorage.get(key) || null;
} catch (error) {
} catch (error: unknown) {
authError('[AuthStorage] Error reading from storage:', error);
return this.memoryStorage.get(key) || null;
}
@@ -129,7 +129,7 @@ class AuthStorage {
}
// Always keep in memory as backup
this.memoryStorage.set(key, value);
} catch (error) {
} catch (error: unknown) {
authError('[AuthStorage] Error writing to storage:', error);
// Fallback to memory only
this.memoryStorage.set(key, value);
@@ -142,7 +142,7 @@ class AuthStorage {
this.storage.removeItem(key);
}
this.memoryStorage.delete(key);
} catch (error) {
} catch (error: unknown) {
authError('[AuthStorage] Error removing from storage:', error);
this.memoryStorage.delete(key);
}
@@ -183,7 +183,7 @@ class AuthStorage {
// Clear memory storage
this.memoryStorage.clear();
authLog('[AuthStorage] ✓ All auth storage cleared');
} catch (error) {
} catch (error: unknown) {
authError('[AuthStorage] Error clearing storage:', error);
// Still clear memory storage as fallback
this.memoryStorage.clear();

View File

@@ -108,7 +108,7 @@ export async function handleExtendLock(
action: 'lock_extended',
submissionId,
});
} catch (error) {
} catch (error: unknown) {
logger.error('Failed to extend lock', {
action: 'extend_lock_error',
submissionId,

View File

@@ -244,8 +244,8 @@ export async function fetchSubmissions(
submissions: enrichedSubmissions,
totalCount: count || 0,
};
} catch (error) {
console.error('Error fetching submissions:', error);
} catch (error: unknown) {
console.error('Error fetching submissions:', error instanceof Error ? error.message : String(error));
return {
submissions: [],
totalCount: 0,
@@ -281,8 +281,8 @@ export async function fetchUserProfiles(
}
return new Map(profiles?.map(p => [p.user_id, p]) || []);
} catch (error) {
console.error('Failed to fetch user profiles:', error);
} catch (error: unknown) {
console.error('Failed to fetch user profiles:', error instanceof Error ? error.message : String(error));
return new Map();
}
}
@@ -385,8 +385,8 @@ export async function getQueueStats(
escalated,
total,
};
} catch (error) {
console.error('Error fetching queue stats:', error);
} catch (error: unknown) {
console.error('Error fetching queue stats:', error instanceof Error ? error.message : String(error));
return {
pending: 0,
flagged: 0,

View File

@@ -28,7 +28,7 @@ class NotificationService {
.maybeSingle();
return !!data?.setting_value;
} catch (error) {
} catch (error: unknown) {
logger.error('Failed to check Novu status', {
action: 'check_novu_status',
error: error instanceof Error ? error.message : String(error)
@@ -80,7 +80,7 @@ class NotificationService {
});
return { success: true };
} catch (error) {
} catch (error: unknown) {
logger.error('Error in updateSubscriber', {
action: 'update_novu_subscriber',
userId: subscriberData.subscriberId,
@@ -162,7 +162,7 @@ class NotificationService {
});
return { success: true };
} catch (error) {
} catch (error: unknown) {
logger.error('Error in createSubscriber', {
action: 'create_novu_subscriber',
userId: subscriberData.subscriberId,
@@ -258,7 +258,7 @@ class NotificationService {
});
return { success: true };
} catch (error) {
} catch (error: unknown) {
logger.error('Error updating notification preferences', {
action: 'update_notification_preferences',
userId,
@@ -314,7 +314,7 @@ class NotificationService {
workflowPreferences: data.workflow_preferences,
frequencySettings: data.frequency_settings
});
} catch (error) {
} catch (error: unknown) {
logger.error('Error fetching notification preferences', {
action: 'fetch_notification_preferences',
userId,
@@ -345,7 +345,7 @@ class NotificationService {
}
return data || [];
} catch (error) {
} catch (error: unknown) {
logger.error('Error fetching notification templates', {
action: 'fetch_notification_templates',
error: error instanceof Error ? error.message : String(error)
@@ -394,7 +394,7 @@ class NotificationService {
});
return { success: true };
} catch (error) {
} catch (error: unknown) {
logger.error('Error triggering notification', {
action: 'trigger_notification',
workflowId: payload.workflowId,
@@ -439,7 +439,7 @@ class NotificationService {
submissionId: payload.submission_id,
requestId
});
} catch (error) {
} catch (error: unknown) {
logger.error('Error notifying moderators', {
action: 'notify_moderators',
submissionId: payload.submission_id,

View File

@@ -60,7 +60,7 @@ export async function trackRequest<T>(
return { result, requestId: context.requestId, duration };
} catch (error) {
} catch (error: unknown) {
const duration = Date.now() - start;
const errorInfo = error instanceof Error
? { type: error.name, message: error.message }

View File

@@ -254,8 +254,8 @@ export async function clearTestData(): Promise<{ deleted: number }> {
}
return { deleted: submissionCount };
} catch (error) {
console.error('Error clearing test data:', error);
} catch (error: unknown) {
console.error('Error clearing test data:', error instanceof Error ? error.message : String(error));
throw error;
}
}

View File

@@ -39,7 +39,7 @@ export async function trackPageView(
entity_id: entityId,
session_hash: getSessionHash()
});
} catch (error) {
} catch (error: unknown) {
// Fail silently - don't break the page if tracking fails
logger.error('Failed to track page view', { entityType, entityId });
}