Improve error handling and data assignment in test data seeding

Fixes TypeScript errors in the seed data edge function by correctly assigning `userId` instead of `user.id` and safely accessing error messages.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: a8c5cf3e-a80e-462f-b090-b081acdcf03a
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
pac7
2025-10-08 13:56:00 +00:00
parent 9eb5e61d4a
commit 543e7fe81e
2 changed files with 41 additions and 2 deletions

View File

@@ -0,0 +1,38 @@
1. TypeScript Errors in Seed Data Edge Function
File: supabase/functions/seed-test-data/index.ts
Line 125: Accessing user.id when user is possibly null
Line 286: Accessing error.message when error is type unknown
Impact: These will cause runtime errors when the function executes under certain conditions
2. Hot Module Replacement (HMR) Failures
Files: src/pages/ManufacturerRides.tsx and src/pages/ManufacturerModels.tsx
Issue: Recent changes caused syntax errors preventing hot reload
Impact: Development workflow is broken for these pages
🟠 High Priority Issues
3. Potential Null Pointer Errors
src/hooks/useNovuNotifications.ts: user?.id could be undefined when authentication state changes unexpectedly
src/components/admin/LocationSearch.tsx: setSelectedLocation(null) might cause issues in consuming components
src/components/admin/RideModelForm.tsx & ManufacturerForm.tsx: Using empty string '' as default for IDs instead of undefined or null
4. Race Conditions
src/hooks/useEntityVersions.ts: Multiple fetches could complete out of order without explicit handling
src/components/upload/PhotoUpload.tsx: Multi-file uploads with Promise.all could leave partial state on failures
src/lib/systemActivityService.ts: Real-time subscription updates could conflict with ongoing data fetches
5. Error Handling Gaps
Edge Functions: Several edge functions (upload-image, trigger-notification, update-novu-preferences) lack granular error handling around critical API calls
React Components: Some async operations in components don't have comprehensive error handling
🟡 Medium Priority Issues
6. Type Safety Issues
src/components/search/AutocompleteSearch.tsx: Type assertion as SearchResult could be unsafe if object structure differs
src/components/companyHelpers.ts: extractImageAssignments assumes data.images.uploaded is always an array without validation
7. Memory Management Concerns
src/hooks/useModerationQueue.ts: setInterval for polling queue stats (line 39) - cleanup appears to be present but verify it's working correctly
Note: useAuth hook cleanup is properly implemented ✅
8. Input Validation
Various forms default person_type to 'company' which might cause issues if it's not always a valid enum value

View File

@@ -122,7 +122,7 @@ Deno.serve(async (req) => {
} }
if (options.expiredLock) { if (options.expiredLock) {
submissionData.assigned_to = user.id; submissionData.assigned_to = userId;
submissionData.locked_until = new Date(Date.now() - 1000 * 60 * 30).toISOString(); // 30 min ago submissionData.locked_until = new Date(Date.now() - 1000 * 60 * 30).toISOString(); // 30 min ago
} }
@@ -282,8 +282,9 @@ Deno.serve(async (req) => {
} catch (error) { } catch (error) {
console.error('Seed error:', error); console.error('Seed error:', error);
const errorMessage = error instanceof Error ? error.message : 'An unknown error occurred';
return new Response( return new Response(
JSON.stringify({ error: error.message }), JSON.stringify({ error: errorMessage }),
{ status: 500, headers: { ...corsHeaders, 'Content-Type': 'application/json' } } { status: 500, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
); );
} }