-
Notifications
You must be signed in to change notification settings - Fork 0
feat(error): implement comprehensive error handling and logging system #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /** | ||
| * Error Boundary Component | ||
| * | ||
| * React error boundary that catches errors in child components | ||
| * and displays a fallback UI. | ||
| */ | ||
|
|
||
| import { Component, type ErrorInfo, type ReactNode } from 'react'; | ||
| import { logger } from '@/lib/logger'; | ||
| import { ErrorFallback } from './ErrorFallback'; | ||
|
|
||
| interface Props { | ||
| children: ReactNode; | ||
| fallback?: ReactNode; | ||
| onError?: (error: Error, errorInfo: ErrorInfo) => void; | ||
| resetKeys?: unknown[]; | ||
| } | ||
|
|
||
| interface State { | ||
| hasError: boolean; | ||
| error: Error | null; | ||
| errorInfo: ErrorInfo | null; | ||
| } | ||
|
|
||
| export class ErrorBoundary extends Component<Props, State> { | ||
| constructor(props: Props) { | ||
| super(props); | ||
| this.state = { | ||
| hasError: false, | ||
| error: null, | ||
| errorInfo: null, | ||
| }; | ||
| } | ||
|
|
||
| static getDerivedStateFromError(error: Error): Partial<State> { | ||
| return { hasError: true, error }; | ||
| } | ||
|
|
||
| componentDidCatch(error: Error, errorInfo: ErrorInfo): void { | ||
| // Log the error | ||
| logger.error('React Error Boundary caught an error', error, { | ||
| componentStack: errorInfo.componentStack, | ||
| }); | ||
|
|
||
| // Update state with error info | ||
| this.setState({ errorInfo }); | ||
|
|
||
| // Call optional error callback | ||
| this.props.onError?.(error, errorInfo); | ||
| } | ||
|
|
||
| componentDidUpdate(prevProps: Props): void { | ||
| // Reset error state when resetKeys change | ||
| if (this.state.hasError && this.props.resetKeys) { | ||
| const hasResetKeyChanged = this.props.resetKeys.some( | ||
| (key, index) => key !== prevProps.resetKeys?.[index] | ||
| ); | ||
|
|
||
| if (hasResetKeyChanged) { | ||
| this.resetErrorBoundary(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resetErrorBoundary = (): void => { | ||
| this.setState({ | ||
| hasError: false, | ||
| error: null, | ||
| errorInfo: null, | ||
| }); | ||
| }; | ||
|
|
||
| render(): ReactNode { | ||
| if (this.state.hasError) { | ||
| // Use custom fallback if provided | ||
| if (this.props.fallback) { | ||
| return this.props.fallback; | ||
| } | ||
|
|
||
| // Use default error fallback | ||
| return ( | ||
| <ErrorFallback | ||
| error={this.state.error} | ||
| componentStack={this.state.errorInfo?.componentStack} | ||
| onRetry={this.resetErrorBoundary} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| return this.props.children; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Hook-friendly wrapper for error boundary | ||
| */ | ||
| export function withErrorBoundary<P extends object>( | ||
| WrappedComponent: React.ComponentType<P>, | ||
| fallback?: ReactNode | ||
| ) { | ||
| return function WithErrorBoundary(props: P) { | ||
| return ( | ||
| <ErrorBoundary fallback={fallback}> | ||
| <WrappedComponent {...props} /> | ||
| </ErrorBoundary> | ||
| ); | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| /** | ||
| * Error Fallback Component | ||
| * | ||
| * User-friendly error display with retry functionality. | ||
| * Follows ThumbCode's organic design language. | ||
| */ | ||
|
|
||
| import { Alert, Pressable, View } from 'react-native'; | ||
| import { useSafeAreaInsets } from 'react-native-safe-area-context'; | ||
| import { Container, VStack } from '@/components/layout'; | ||
| import { Text } from '@/components/ui'; | ||
|
|
||
| interface ErrorFallbackProps { | ||
| error: Error | null; | ||
| componentStack?: string | null; | ||
| onRetry?: () => void; | ||
| onReportIssue?: () => void; | ||
| title?: string; | ||
| message?: string; | ||
| } | ||
|
|
||
| export function ErrorFallback({ | ||
| error, | ||
| componentStack, | ||
| onRetry, | ||
| onReportIssue, | ||
| title = 'Something went wrong', | ||
| message = "We're sorry, but something unexpected happened. Please try again.", | ||
| }: ErrorFallbackProps) { | ||
| const insets = useSafeAreaInsets(); | ||
| const isDev = __DEV__; | ||
|
|
||
| const handleReportIssue = () => { | ||
| if (onReportIssue) { | ||
| onReportIssue(); | ||
| } else { | ||
| // TODO: Implement proper issue reporting (e.g., open GitHub issues URL) | ||
| Alert.alert('Report Issue', 'Issue reporting will be available in a future update.'); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <View | ||
| className="flex-1 bg-charcoal" | ||
| style={{ paddingTop: insets.top, paddingBottom: insets.bottom }} | ||
| > | ||
| <Container padding="lg" className="flex-1 justify-center"> | ||
| <VStack spacing="lg" align="center"> | ||
| {/* Error Icon */} | ||
| <View | ||
| className="w-20 h-20 bg-coral-500/20 items-center justify-center" | ||
| style={{ | ||
| borderTopLeftRadius: 40, | ||
| borderTopRightRadius: 36, | ||
| borderBottomRightRadius: 42, | ||
| borderBottomLeftRadius: 38, | ||
| }} | ||
| > | ||
| <Text className="text-4xl">⚠️</Text> | ||
| </View> | ||
|
|
||
| {/* Error Title */} | ||
| <Text size="xl" weight="bold" className="text-white text-center font-display"> | ||
| {title} | ||
| </Text> | ||
|
|
||
| {/* Error Message */} | ||
| <Text className="text-neutral-400 text-center max-w-xs">{message}</Text> | ||
|
|
||
| {/* Dev-only Error Details */} | ||
| {isDev && error && ( | ||
| <View | ||
| className="bg-surface p-4 w-full max-w-sm" | ||
| style={{ | ||
| borderTopLeftRadius: 12, | ||
| borderTopRightRadius: 10, | ||
| borderBottomRightRadius: 14, | ||
| borderBottomLeftRadius: 8, | ||
| }} | ||
| > | ||
| <Text size="sm" weight="semibold" className="text-coral-500 mb-2"> | ||
| Debug Info | ||
| </Text> | ||
| <Text size="sm" className="text-neutral-400 font-mono mb-2"> | ||
| {error.name}: {error.message} | ||
| </Text> | ||
| {componentStack && ( | ||
| <Text size="xs" className="text-neutral-500 font-mono" numberOfLines={8}> | ||
| {componentStack} | ||
| </Text> | ||
| )} | ||
| </View> | ||
| )} | ||
|
|
||
| {/* Retry Button */} | ||
| {onRetry && ( | ||
| <Pressable | ||
| onPress={onRetry} | ||
| className="bg-coral-500 px-8 py-3 active:bg-coral-600" | ||
| style={{ | ||
| borderTopLeftRadius: 24, | ||
| borderTopRightRadius: 22, | ||
| borderBottomRightRadius: 26, | ||
| borderBottomLeftRadius: 20, | ||
| }} | ||
| > | ||
| <Text weight="semibold" className="text-white"> | ||
| Try Again | ||
| </Text> | ||
| </Pressable> | ||
| )} | ||
|
|
||
| {/* Secondary Action */} | ||
| <Pressable className="py-2" onPress={handleReportIssue}> | ||
| <Text size="sm" className="text-teal-500"> | ||
| Report Issue | ||
| </Text> | ||
| </Pressable> | ||
| </VStack> | ||
| </Container> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Compact error fallback for inline use | ||
| */ | ||
| interface CompactErrorFallbackProps { | ||
| message?: string; | ||
| onRetry?: () => void; | ||
| } | ||
|
|
||
| export function CompactErrorFallback({ | ||
| message = 'Failed to load', | ||
| onRetry, | ||
| }: CompactErrorFallbackProps) { | ||
| return ( | ||
| <View | ||
| className="bg-surface/50 p-4" | ||
| style={{ | ||
| borderTopLeftRadius: 12, | ||
| borderTopRightRadius: 10, | ||
| borderBottomRightRadius: 14, | ||
| borderBottomLeftRadius: 8, | ||
| }} | ||
| > | ||
| <VStack spacing="sm" align="center"> | ||
| <Text size="sm" className="text-neutral-400"> | ||
| {message} | ||
| </Text> | ||
| {onRetry && ( | ||
| <Pressable onPress={onRetry}> | ||
| <Text size="sm" className="text-teal-500"> | ||
| Tap to retry | ||
| </Text> | ||
| </Pressable> | ||
| )} | ||
| </VStack> | ||
| </View> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| /** | ||
| * Error Components | ||
| * | ||
| * Components for error handling and display. | ||
| */ | ||
|
|
||
| export { ErrorBoundary, withErrorBoundary } from './ErrorBoundary'; | ||
| export { CompactErrorFallback, ErrorFallback } from './ErrorFallback'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
@react-native-community/netinfo 11.4.1 React Native 0.76.0 compatibility requirements💡 Result:
Short answer: Yes —
@react-native-community/netinfo11.4.1 is compatible with React Native 0.76. The package supports React Native >= 0.60 (autolinking) and lists react-native as a peer dependency; RN 0.76 meets that requirement. [1][2]Sources:
References:
[1] npm package README for
@react-native-community/netinfo.[2] jsDocs / npm metadata for
@react-native-community/netinfov11.4.1.🌐 Web query:
@react-native-async-storage/async-storage 2.0.0 React Native 0.76.0 compatibility💡 Result:
Short answer: Generally yes —
@react-native-async-storage/async-storagev2.x supports React Native >=0.60 (so it should work with RN 0.76.0). [1][2]Notes and cautions:
Recommendations:
@react-native-async-storage/async-storage2.x (not exactly 2.0.0) if possible. [3]Sources:
[1] Async Storage install docs (requires RN 0.60+).
[2] GitHub issue reporting Kotlin/KSP compatibility with version 2.0.0.
[3] npm package page showing newer 2.x releases (e.g., 2.2.0).
Upgrade
@react-native-async-storage/async-storageto the latest 2.x patch version (≥2.2.0).While
@react-native-community/netinfo@^11.4.1is compatible with React Native 0.76.0,@react-native-async-storage/async-storage@2.0.0has documented Android build issues with Kotlin 2.x/KSP toolchains (reported as "ksp is too old for kotlin-2" errors). Upgrade to a newer 2.x patch release (e.g., 2.2.0 or later) to avoid potential Android build failures.🤖 Prompt for AI Agents