DEBUG SYNC ERRORS
Ecosistema completo para organización y gestión de contenido con interfaces espaciales
🔍 Enhanced Error Logging - Debug Guide
Date: November 18, 2025
Purpose: Help identify the exact cause of sync failures
📋 What Changed
Added detailed logging to SyncEngineService.syncOperationToBackend() to capture:
- HTTP Status Code (
httpStatus) - HTTP Status Text (
httpStatusText) - Error Message (
errorMessage) - Error Details (
errorDetails) - Operation Type (space vs universe)
- Operation Action (create/update/delete)
- Data validation state
🔍 What to Look For in Console
Step-by-Step Logging
When a sync operation runs, you'll now see:
[SyncEngine] 🔄 Syncing operation to backend: { operation: "update", entity: "universe", key: "universe_..." }
[SyncEngine] 🌌 Processing universe operation
[SyncEngine] 🌌 Universe sync details: { operation: "update", universeId: "...", spaceId: "...", universeName: "..." }
[SyncEngine] 📤 Calling SpaceApiService.updateUniverse
If successful:
[SpaceApiService] Updating universe: { spaceId: "...", universeId: "...", name: "..." }
✅ Universe updated: universe_...
[SyncEngine] ✅ Universe updated in backend: { universeId: "...", spaceId: "...", name: "..." }
If it fails, you'll see:
[SpaceApiService] Failed to update universe: HttpErrorResponse {...}
[SyncEngine] ❌ Failed to sync operation: {
operation: "update",
entity: "universe",
key: "universe_...",
hasData: true,
dataType: "object",
httpStatus: 401, // ← KEY: The HTTP status code
httpStatusText: "Unauthorized", // ← KEY: The status text
errorMessage: "...", // ← KEY: The error message
errorDetails: "..." // ← KEY: Backend error details
}
🎯 Key Information to Check
1. HTTP Status Code
| Code | Meaning | Likely Cause |
|---|---|---|
| 401 | Unauthorized | Token missing/expired/invalid |
| 403 | Forbidden | User lacks permission |
| 404 | Not Found | Endpoint doesn't exist or ID wrong |
| 422 | Unprocessable Entity | Data validation failed |
| 500 | Internal Server Error | Backend crash/bug |
2. Which Operation is Failing?
Look for the last successful log before the error:
If you see:
[SyncEngine] 📤 Calling SpaceApiService.updateSpace
❌ Failed to sync operation: { entity: "space", ... }
→ Space update failing
If you see:
[SyncEngine] 📤 Calling SpaceApiService.createUniverse
❌ Failed to sync operation: { entity: "universe", operation: "create", ... }
→ Universe creation failing
If you see:
[SyncEngine] 📤 Calling SpaceApiService.updateUniverse
❌ Failed to sync operation: { entity: "universe", operation: "update", ... }
→ Universe update failing
3. Data Validation
If you see these errors BEFORE the HTTP call:
❌ Cannot sync space: missing space.id in operation.data
❌ Cannot sync universe: operation.data is undefined
❌ Cannot sync universe ...: missing spaceId in data
→ Corrupted sync queue operation (will be auto-removed)
🧪 Testing Steps
Step 1: Clear Browser Cache
- Open DevTools → Application → Local Storage
- Find
syncQueuekey - Check if there are old operations from before the fix
- If yes, delete them manually OR clear all local storage
Step 2: Create a New Universe
- Click "New Universe"
- Name it:
test-error-logging - Create it
- Watch console carefully
Step 3: Analyze the Logs
Look for this sequence:
✅ GOOD: Complete success
------------------------------------------------------------
[SyncEngine] 🔄 Syncing operation to backend: { operation: "create", entity: "universe" }
[SyncEngine] 🌌 Processing universe operation
[SyncEngine] 🌌 Universe sync details: { operation: "create", universeId: "...", spaceId: "...", universeName: "test-error-logging" }
[SyncEngine] 📤 Calling SpaceApiService.createUniverse
🔐 Auth Interceptor: Added JWT token to request
[SpaceApiService] Creating universe: { spaceId: "...", universeId: "...", name: "test-error-logging" }
[SpaceApiService] ✅ Universe created: universe_...
[SyncEngine] ✅ Universe created in backend
❌ BAD: Auth failure
------------------------------------------------------------
[SyncEngine] 📤 Calling SpaceApiService.createUniverse
[SpaceApiService] Failed to create universe: HttpErrorResponse
[SyncEngine] ❌ Failed to sync operation: {
httpStatus: 401,
httpStatusText: "Unauthorized",
errorMessage: "Unauthorized",
errorDetails: { message: "Invalid token" } ← Look here!
}
❌ BAD: Validation failure
------------------------------------------------------------
[SyncEngine] 🌌 Processing universe operation
[SyncEngine] ❌ Failed to sync operation: {
httpStatus: "N/A",
errorMessage: "Cannot sync universe ...: missing spaceId in data"
}
🔧 Troubleshooting Guide
If you see httpStatus: 401
Problem: Authentication token issue
Solutions:
- Check if logged in:
localStorage.getItem('auth_token') - Check token expiry: Decode JWT at jwt.io
- Try logging out and back in
- Check if
AuthServiceis being used (notBackendAuthAdapterService)
If you see httpStatus: 404
Problem: Endpoint doesn't exist or wrong ID
Check:
- Is backend deployed to Railway?
- Is the endpoint URL correct in logs?
- Does the spaceId/universeId exist in MongoDB?
If you see httpStatus: 500
Problem: Backend error
Check:
- Railway logs for backend errors
- MongoDB connection status
- Backend console for stack traces
If you see errorMessage: "Cannot sync ..."
Problem: Corrupted sync queue operation
Solution:
- This is automatically removed from queue
- Check if corruption detection logged:
🧹 Removing unrecoverably corrupted ... operation
📊 Success Checklist
After fixes, you should see:
- ✅
httpStatus: 200or201(not 401) - ✅
✅ Universe created/updated in backend - ✅
✅ Space synced to backend - ✅ No retry loops
- ✅ MongoDB shows updated data
📝 Report Template
When reporting errors, please provide:
**HTTP Status**: [from httpStatus field]
**Operation**: [create/update/delete]
**Entity**: [space/universe]
**Error Message**: [from errorMessage field]
**Error Details**: [from errorDetails field]
**Full Log Sequence**: [copy entire sequence from console]
Example:
**HTTP Status**: 401
**Operation**: update
**Entity**: universe
**Error Message**: Unauthorized
**Error Details**: { message: "Invalid token" }
**Full Log Sequence**:
[SyncEngine] 📤 Calling SpaceApiService.updateUniverse
[SpaceApiService] Failed to update universe: HttpErrorResponse
[SyncEngine] ❌ Failed to sync operation: { httpStatus: 401, ... }
🎯 Next Steps
- Clear local storage to remove old sync queue
- Try creating a universe and watch console
- Share the console logs showing:
httpStatuserrorMessageerrorDetails
- Check Network tab in DevTools for request/response details
With this enhanced logging, we can now pinpoint the EXACT cause of any sync failure! 🎯