Fix remaining console logs and types

This commit is contained in:
gpt-engineer-app[bot]
2025-11-03 20:04:11 +00:00
parent 6fbaf0c606
commit 2cd6b2c6c3
10 changed files with 127 additions and 42 deletions

View File

@@ -340,25 +340,84 @@ logger.error('Payment failed', {
---
## Summary
## Edge Function Logging
**Use `handleError()` for all application errors** - Logs to Admin Panel
**Use `logger.*` for non-error logging** - Structured and filterable
**Provide rich context with every log** - Makes debugging easier
**Use appropriate log levels (debug/info/warn/error)** - Environment-aware
**Let ESLint catch violations early** - No console statements allowed
**Never log sensitive data (passwords, tokens, PII)** - Security critical
**Re-throw errors after handleError()** - Let parent error boundaries catch them
### Using `edgeLogger` in Edge Functions
Edge functions use the `edgeLogger` utility from `_shared/logger.ts`:
```typescript
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
const handler = async (req: Request): Promise<Response> => {
const tracking = startRequest('function-name');
try {
edgeLogger.info('Processing request', {
requestId: tracking.requestId,
// ... context
});
// ... your code
const duration = endRequest(tracking);
edgeLogger.info('Request completed', { requestId: tracking.requestId, duration });
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
const duration = endRequest(tracking);
edgeLogger.error('Request failed', {
error: errorMessage,
requestId: tracking.requestId,
duration
});
}
};
```
### Logger Methods for Edge Functions
- `edgeLogger.info()` - General information logging
- `edgeLogger.warn()` - Warning conditions
- `edgeLogger.error()` - Error conditions
- `edgeLogger.debug()` - Detailed debugging (dev only)
All logs are visible in the Supabase Edge Function Logs dashboard.
**CRITICAL**: Never use `console.*` in edge functions. Always use `edgeLogger.*` instead.
---
## Summary
**Use `handleError()` for application errors** → Logs to Admin Panel + user-friendly toast
**Use `logger.*` for general logging (client-side)** → Environment-aware console output
**Use `edgeLogger.*` for edge function logging** → Structured logs visible in Supabase dashboard
**Never use `console.*`** → Blocked by ESLint
This approach ensures:
- ✅ Production builds are clean (no console noise)
- ✅ All errors are tracked and actionable in Admin Panel
- ✅ Users get helpful error messages with reference IDs
- ✅ Development remains productive with detailed logs
- ✅ Edge functions have structured, searchable logs
## Admin Panel Error Monitoring
All errors logged via `handleError()` are visible in the Admin Panel:
- **URL**: `/admin/error-monitoring`
- **Features**: Search by user, action, date, error type
- **Reference IDs**: Each error has a unique ID shown to users
- **Context**: Full metadata and breadcrumbs for debugging
All errors logged via `handleError()` are visible in the Admin Panel at:
**Path**: `/admin/error-monitoring`
**Features**:
- Search and filter errors by action, user, date range
- View error context (metadata, breadcrumbs, environment)
- Track error frequency and patterns
- One-click copy of error details for debugging
**Access**: Admin role required
---
**Updated**: 2025-11-03
**Status**: ✅ Enforced via ESLint (Frontend + Edge Functions)
---

View File

@@ -11,12 +11,13 @@
**Status**: ✅ **100% COMPLIANT**
- ✅ All `console.error()` replaced with `handleError()` or `logger.error()`
- ✅ All `console.log()` replaced with `logger.info()` or `logger.debug()`
- ✅ All `console.warn()` replaced with `logger.warn()`
- ✅ All `console.error()` replaced with `handleError()`, `logger.error()`, or `edgeLogger.error()`
- ✅ All `console.log()` replaced with `logger.info()`, `logger.debug()`, or `edgeLogger.info()`
- ✅ All `console.warn()` replaced with `logger.warn()` or `edgeLogger.warn()`
-`authLogger.ts` refactored to use `logger` internally
- ✅ All edge functions updated to use `edgeLogger.*` (validate-email, validate-email-backend, update-novu-preferences, upload-image)
- ✅ ESLint `no-console` rule strengthened to block ALL console statements
- ✅ 34 files updated with structured logging
- ✅ 38+ files updated with structured logging (frontend + edge functions)
**Files Fixed**:
- `src/hooks/useBanCheck.ts`
@@ -120,9 +121,11 @@ Relational data incorrectly stored as JSONB:
| Category | Status | Progress |
|----------|--------|----------|
| Console Statements | ✅ Complete | 100% |
| Console Statements (Frontend) | ✅ Complete | 100% |
| Console Statements (Edge Functions) | ✅ Complete | 100% |
| Error Handling | ✅ Complete | 100% |
| Structured Logging | ✅ Complete | 100% |
| TypeScript `any` Types (Critical) | ✅ Complete | 100% |
| ESLint Rules | ✅ Enforced | 100% |
| JSONB Elimination | ⚠️ In Progress | 57% (11 acceptable, 4 migrated, 15 remaining) |
| Documentation | ✅ Complete | 100% |
@@ -153,8 +156,9 @@ WHERE data_type = 'jsonb'
## 📝 Notes
- **Console Statements**: Zero tolerance policy enforced via ESLint
- **Error Handling**: All application errors MUST use `handleError()` to log to Admin Panel
- **Console Statements**: Zero tolerance policy enforced via ESLint (frontend + edge functions)
- **Error Handling**: All application errors MUST use `handleError()` (frontend) or `edgeLogger.error()` (edge functions)
- **TypeScript `any` Types**: Critical violations fixed in error handlers, auth components, data mapping, and form schemas
- **JSONB Violations**: Require database migrations - need user approval before proceeding
- **Testing**: All changes verified with existing test suites