-
Notifications
You must be signed in to change notification settings - Fork 0
Error Handling
Cameron Rye edited this page Nov 19, 2025
·
1 revision
DosKit implements a comprehensive, multi-layered error handling strategy to ensure a robust user experience and facilitate debugging.
- Global Error Handler - Captures uncaught errors and unhandled promise rejections
- React Error Boundaries - Catches React component errors
- Component-Level Error States - Local error handling in components
- Error Tracking Service - Centralized error reporting and monitoring
- User-Friendly Error Messages - Maps technical errors to readable messages
File: src/utils/globalErrorHandler.ts
Purpose: Captures all uncaught errors and unhandled promise rejections at the window level.
Features:
- Captures
window.onerrorevents - Captures
window.onunhandledrejectionevents - Filters out known harmless errors (fullscreen API, keyboard lock, etc.)
- Provides error context (browser info, timestamp, user action)
- Integrates with error tracking service
Usage:
import { initializeGlobalErrorHandler } from './utils/globalErrorHandler';
initializeGlobalErrorHandler({
showUserFriendlyErrors: true,
suppressHarmlessErrors: true,
onError: (error, context) => {
console.error('Error captured:', error, context);
},
});File: src/utils/errorTracking.ts
Purpose: Abstraction layer for error tracking services (Sentry, LogRocket, etc.)
Features:
- Service-agnostic interface
- Console tracker for development
- Sentry tracker placeholder for production
- Error severity levels (DEBUG, INFO, WARNING, ERROR, FATAL)
- Error context tracking
- Breadcrumb support for user action trails
Usage:
import { initializeErrorTracking, getErrorTracker, ErrorSeverity } from './utils/errorTracking';
// Initialize (in main.tsx)
initializeErrorTracking('console'); // or 'sentry' with config
// Use in code
const tracker = getErrorTracker();
tracker.captureError(error, { userAction: 'Loading app' }, ErrorSeverity.ERROR);
tracker.addBreadcrumb('User clicked load button', 'user-action');File: src/components/ErrorBoundary.tsx
Purpose: Catches React component errors and prevents full app crashes
Features:
- Catches errors in React component tree
- Displays fallback UI with error details (dev mode)
- Integrates with error tracking service
- Provides reset functionality
Usage:
import { ErrorBoundary } from './components/ErrorBoundary';
<ErrorBoundary>
<App />
</ErrorBoundary>File: src/utils/errorMessages.ts
Purpose: Maps technical errors to user-friendly messages
Features:
- Pattern matching for common errors
- Provides suggestions for resolution
- Includes original error in dev mode
- Extensible error mappings
Usage:
import { getUserFriendlyError } from './utils/errorMessages';
try {
await fetchData();
} catch (error) {
const friendly = getUserFriendlyError(error);
console.error(friendly.message);
if (friendly.suggestion) {
console.info(friendly.suggestion);
}
}Error occurs
↓
Global Error Handler captures
↓
Check if harmless → Suppress if yes
↓
Log to console (logger)
↓
Track with error tracking service
↓
Show user-friendly message (if enabled)
Error in React component
↓
Error Boundary catches
↓
Update state (hasError = true)
↓
Track with error tracking service
↓
Render fallback UI
const handleLoadApp = async () => {
try {
await loadApp();
} catch (error) {
const friendly = getUserFriendlyError(error);
setError(friendly.message);
getErrorTracker().captureError(error, { userAction: 'Loading app' });
}
};tracker.captureError(error, {
userAction: 'Loading Second Reality demo',
component: 'DemoSelector',
metadata: { appId: 'second-reality' },
});tracker.addBreadcrumb('User selected app', 'user-action', { appId: 'doom' });<ErrorBoundary>
<DosPlayer />
</ErrorBoundary>- Architecture - Technical architecture
- State Management - State management guide
- Troubleshooting - Common issues
Made with ❤️ by Cameron Rye