Files
supervisor-ui/components/providers/Providers.tsx

44 lines
1.2 KiB
TypeScript
Raw Normal View History

'use client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
feat(logging): add comprehensive error boundary and global error handling (Phase 6) Implemented complete client-side error handling and reporting system: Error Boundary Component (components/providers/ErrorBoundary.tsx): - React Error Boundary to catch component errors - Automatic error logging to client logger - Error reporting to server endpoint - User-friendly fallback UI with error details (dev mode) - Reset and reload functionality - Custom fallback support via props Global Error Handler (lib/utils/global-error-handler.ts): - Window error event listener for uncaught errors - Unhandled promise rejection handler - Automatic error reporting to server - Comprehensive error metadata collection: - Error message and stack trace - URL, user agent, timestamp - Filename, line number, column number (for window errors) Client Error Reporting Endpoint (app/api/client-error/route.ts): - Server-side endpoint to receive client errors - Integrated with withLogging() for automatic server logging - Accepts error reports from both ErrorBoundary and global handlers - Returns acknowledgement to client Error Boundary Integration (components/providers/Providers.tsx): - Wrapped entire app in ErrorBoundary - Initialized global error handlers on mount - Catches React errors, window errors, and unhandled rejections Error Reporting Features: - Duplicate error tracking prevention - Async error reporting (non-blocking) - Graceful degradation (fails silently if reporting fails) - Development vs production error display - Structured error metadata for debugging All errors now: - Log to browser console via client logger - Report to server for centralized logging - Display user-friendly error UI - Include full context for debugging - Work across React, window, and promise contexts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 21:00:37 +01:00
import { useState, ReactNode, useEffect } from 'react';
import { Toaster } from 'sonner';
import { ThemeProvider } from './ThemeProvider';
feat(logging): add comprehensive error boundary and global error handling (Phase 6) Implemented complete client-side error handling and reporting system: Error Boundary Component (components/providers/ErrorBoundary.tsx): - React Error Boundary to catch component errors - Automatic error logging to client logger - Error reporting to server endpoint - User-friendly fallback UI with error details (dev mode) - Reset and reload functionality - Custom fallback support via props Global Error Handler (lib/utils/global-error-handler.ts): - Window error event listener for uncaught errors - Unhandled promise rejection handler - Automatic error reporting to server - Comprehensive error metadata collection: - Error message and stack trace - URL, user agent, timestamp - Filename, line number, column number (for window errors) Client Error Reporting Endpoint (app/api/client-error/route.ts): - Server-side endpoint to receive client errors - Integrated with withLogging() for automatic server logging - Accepts error reports from both ErrorBoundary and global handlers - Returns acknowledgement to client Error Boundary Integration (components/providers/Providers.tsx): - Wrapped entire app in ErrorBoundary - Initialized global error handlers on mount - Catches React errors, window errors, and unhandled rejections Error Reporting Features: - Duplicate error tracking prevention - Async error reporting (non-blocking) - Graceful degradation (fails silently if reporting fails) - Development vs production error display - Structured error metadata for debugging All errors now: - Log to browser console via client logger - Report to server for centralized logging - Display user-friendly error UI - Include full context for debugging - Work across React, window, and promise contexts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 21:00:37 +01:00
import { ErrorBoundary } from './ErrorBoundary';
feat(logging): add comprehensive client-side logging (Phase 5) Created client-side logging infrastructure for React Query and hooks: New Client Logger (lib/utils/client-logger.ts): - Environment-aware logging (debug/info in dev, warn/error in prod) - Structured logging with context objects - Performance timing helpers (time/timeEnd) - Group logging for related operations - Factory functions for hook/query/mutation-specific loggers React Query Configuration (components/providers/Providers.tsx): - Added custom logger to QueryClient - Integrated with client-side logger for consistent formatting - Configured mutation retry defaults SSE Hook Logging (lib/hooks/useEventSource.ts): - Connection lifecycle logging (connect/disconnect/reconnect) - Heartbeat and process update event logging - Error tracking with reconnection attempt details - Exponential backoff logging for reconnections Supervisor Hooks Logging (lib/hooks/useSupervisor.ts): - Added logging to all critical mutation hooks: - Process control (start/stop/restart) - Batch operations (start-all/stop-all/restart-all) - Configuration reload - Signal operations - Logs mutation start, success, and error states - Includes contextual metadata (process names, signals, etc.) All client-side logs: - Use structured format with timestamps - Include relevant context for debugging - Respect environment (verbose in dev, minimal in prod) - Compatible with browser devtools 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 20:57:24 +01:00
import { clientLogger } from '@/lib/utils/client-logger';
feat(logging): add comprehensive error boundary and global error handling (Phase 6) Implemented complete client-side error handling and reporting system: Error Boundary Component (components/providers/ErrorBoundary.tsx): - React Error Boundary to catch component errors - Automatic error logging to client logger - Error reporting to server endpoint - User-friendly fallback UI with error details (dev mode) - Reset and reload functionality - Custom fallback support via props Global Error Handler (lib/utils/global-error-handler.ts): - Window error event listener for uncaught errors - Unhandled promise rejection handler - Automatic error reporting to server - Comprehensive error metadata collection: - Error message and stack trace - URL, user agent, timestamp - Filename, line number, column number (for window errors) Client Error Reporting Endpoint (app/api/client-error/route.ts): - Server-side endpoint to receive client errors - Integrated with withLogging() for automatic server logging - Accepts error reports from both ErrorBoundary and global handlers - Returns acknowledgement to client Error Boundary Integration (components/providers/Providers.tsx): - Wrapped entire app in ErrorBoundary - Initialized global error handlers on mount - Catches React errors, window errors, and unhandled rejections Error Reporting Features: - Duplicate error tracking prevention - Async error reporting (non-blocking) - Graceful degradation (fails silently if reporting fails) - Development vs production error display - Structured error metadata for debugging All errors now: - Log to browser console via client logger - Report to server for centralized logging - Display user-friendly error UI - Include full context for debugging - Work across React, window, and promise contexts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 21:00:37 +01:00
import { initGlobalErrorHandlers } from '@/lib/utils/global-error-handler';
export function Providers({ children }: { children: ReactNode }) {
const [queryClient] = useState(
() =>
new QueryClient({
defaultOptions: {
queries: {
staleTime: 3 * 1000, // 3 seconds for real-time feel
refetchOnWindowFocus: false,
retry: 2,
},
feat(logging): add comprehensive client-side logging (Phase 5) Created client-side logging infrastructure for React Query and hooks: New Client Logger (lib/utils/client-logger.ts): - Environment-aware logging (debug/info in dev, warn/error in prod) - Structured logging with context objects - Performance timing helpers (time/timeEnd) - Group logging for related operations - Factory functions for hook/query/mutation-specific loggers React Query Configuration (components/providers/Providers.tsx): - Added custom logger to QueryClient - Integrated with client-side logger for consistent formatting - Configured mutation retry defaults SSE Hook Logging (lib/hooks/useEventSource.ts): - Connection lifecycle logging (connect/disconnect/reconnect) - Heartbeat and process update event logging - Error tracking with reconnection attempt details - Exponential backoff logging for reconnections Supervisor Hooks Logging (lib/hooks/useSupervisor.ts): - Added logging to all critical mutation hooks: - Process control (start/stop/restart) - Batch operations (start-all/stop-all/restart-all) - Configuration reload - Signal operations - Logs mutation start, success, and error states - Includes contextual metadata (process names, signals, etc.) All client-side logs: - Use structured format with timestamps - Include relevant context for debugging - Respect environment (verbose in dev, minimal in prod) - Compatible with browser devtools 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 20:57:24 +01:00
mutations: {
retry: 1,
},
},
})
);
feat(logging): add comprehensive error boundary and global error handling (Phase 6) Implemented complete client-side error handling and reporting system: Error Boundary Component (components/providers/ErrorBoundary.tsx): - React Error Boundary to catch component errors - Automatic error logging to client logger - Error reporting to server endpoint - User-friendly fallback UI with error details (dev mode) - Reset and reload functionality - Custom fallback support via props Global Error Handler (lib/utils/global-error-handler.ts): - Window error event listener for uncaught errors - Unhandled promise rejection handler - Automatic error reporting to server - Comprehensive error metadata collection: - Error message and stack trace - URL, user agent, timestamp - Filename, line number, column number (for window errors) Client Error Reporting Endpoint (app/api/client-error/route.ts): - Server-side endpoint to receive client errors - Integrated with withLogging() for automatic server logging - Accepts error reports from both ErrorBoundary and global handlers - Returns acknowledgement to client Error Boundary Integration (components/providers/Providers.tsx): - Wrapped entire app in ErrorBoundary - Initialized global error handlers on mount - Catches React errors, window errors, and unhandled rejections Error Reporting Features: - Duplicate error tracking prevention - Async error reporting (non-blocking) - Graceful degradation (fails silently if reporting fails) - Development vs production error display - Structured error metadata for debugging All errors now: - Log to browser console via client logger - Report to server for centralized logging - Display user-friendly error UI - Include full context for debugging - Work across React, window, and promise contexts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 21:00:37 +01:00
// Initialize global error handlers once
useEffect(() => {
initGlobalErrorHandlers();
}, []);
return (
feat(logging): add comprehensive error boundary and global error handling (Phase 6) Implemented complete client-side error handling and reporting system: Error Boundary Component (components/providers/ErrorBoundary.tsx): - React Error Boundary to catch component errors - Automatic error logging to client logger - Error reporting to server endpoint - User-friendly fallback UI with error details (dev mode) - Reset and reload functionality - Custom fallback support via props Global Error Handler (lib/utils/global-error-handler.ts): - Window error event listener for uncaught errors - Unhandled promise rejection handler - Automatic error reporting to server - Comprehensive error metadata collection: - Error message and stack trace - URL, user agent, timestamp - Filename, line number, column number (for window errors) Client Error Reporting Endpoint (app/api/client-error/route.ts): - Server-side endpoint to receive client errors - Integrated with withLogging() for automatic server logging - Accepts error reports from both ErrorBoundary and global handlers - Returns acknowledgement to client Error Boundary Integration (components/providers/Providers.tsx): - Wrapped entire app in ErrorBoundary - Initialized global error handlers on mount - Catches React errors, window errors, and unhandled rejections Error Reporting Features: - Duplicate error tracking prevention - Async error reporting (non-blocking) - Graceful degradation (fails silently if reporting fails) - Development vs production error display - Structured error metadata for debugging All errors now: - Log to browser console via client logger - Report to server for centralized logging - Display user-friendly error UI - Include full context for debugging - Work across React, window, and promise contexts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 21:00:37 +01:00
<ErrorBoundary>
<ThemeProvider>
<QueryClientProvider client={queryClient}>
{children}
<Toaster position="top-right" richColors closeButton />
</QueryClientProvider>
</ThemeProvider>
</ErrorBoundary>
);
}