-
Notifications
You must be signed in to change notification settings - Fork 11
Kunal boundary - test #119
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
base: master
Are you sure you want to change the base?
Changes from all commits
bc199e4
862ebc6
e2b0b3c
9e6371a
6e60e8b
6539b6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import React from 'react'; | ||
| import {View, Text, StyleSheet} from 'react-native'; | ||
| import Icon from 'react-native-vector-icons/FontAwesome6'; | ||
| import {StyledButton} from './StyledButton'; | ||
|
|
||
| const BuggyCart = (): React.ReactElement => { | ||
| return ( | ||
| <StyledButton | ||
| testID="add-to-cart-button-error-product" | ||
| title="Add to cart" | ||
| onPress={() => { | ||
| throw new Error('Error boundary triggered from error product card'); | ||
| }} | ||
| style={{ | ||
| default: styles.addToCartButton, | ||
| pressed: styles.addToCartButton, | ||
| }} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export const ErrorBoundaryProduct = (): React.ReactElement => { | ||
| return ( | ||
| <View style={styles.cardContainer}> | ||
| <View style={styles.cardHero}> | ||
| <Icon name="triangle-exclamation" size={48} color="#e74c3c" /> | ||
| </View> | ||
| <View style={styles.cardDetail}> | ||
| <View style={styles.cardDetailContent}> | ||
| <Text style={styles.cardTitle}>Error Product</Text> | ||
| <Text style={styles.cardDescription}>Boundary error testing</Text> | ||
| </View> | ||
| <View style={styles.cardDetailAction}> | ||
| <BuggyCart /> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| cardContainer: { | ||
| width: '100%', | ||
| height: 200, | ||
| borderWidth: 1, | ||
| borderColor: '#e74c3c', | ||
| borderRadius: 6, | ||
| backgroundColor: '#ffffff', | ||
| flex: 1, | ||
| flexDirection: 'row', | ||
| alignItems: 'center', | ||
| justifyContent: 'space-between', | ||
| marginVertical: 5, | ||
| }, | ||
| cardHero: { | ||
| width: '40%', | ||
| height: '100%', | ||
| backgroundColor: '#fdf0f0', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| }, | ||
| cardDetail: { | ||
| flex: 1, | ||
| height: '100%', | ||
| flexDirection: 'column', | ||
| }, | ||
| cardDetailContent: { | ||
| padding: 10, | ||
| flex: 1, | ||
| flexDirection: 'column', | ||
| justifyContent: 'space-between', | ||
| paddingBottom: 10, | ||
| }, | ||
| cardDetailAction: { | ||
| flex: 0, | ||
| }, | ||
| cardTitle: { | ||
| marginBottom: 5, | ||
| fontSize: 24, | ||
| fontWeight: '500', | ||
| color: '#c0392b', | ||
| }, | ||
| cardDescription: { | ||
| fontSize: 14, | ||
| color: '#555', | ||
| }, | ||
| addToCartButton: { | ||
| margin: 10, | ||
| }, | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import {BACKEND_URL} from '../config'; | |
| import {StackScreenProps} from '@react-navigation/stack'; | ||
| import {RootStackParamList} from '../navigation'; | ||
| import {ProfiledStyledProductCard} from '../components/StyledProductCard'; | ||
| import {ErrorBoundaryProduct} from '../components/ErrorBoundaryProduct'; | ||
| import {Product} from '../types/Product'; | ||
|
|
||
| type ExtendedSentryScope = Sentry.Scope & { | ||
|
|
@@ -108,6 +109,7 @@ const EmpowerPlant = ({navigation}: StackScreenProps<RootStackParamList>) => { | |
| refreshing={toolData === null} | ||
| data={toolData} | ||
| contentContainerStyle={styles.productListContainer} | ||
| ListHeaderComponent={toolData ? <ErrorBoundaryProduct /> : null} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The Suggested FixWrap the Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
| renderItem={({item}) => { | ||
| return ( | ||
| <ProfiledStyledProductCard | ||
|
|
||
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.
Bug: The error thrown in the
onPresshandler is not caught bySentry.ErrorBoundary, as error boundaries do not capture errors from event handlers, causing an unhandled exception.Severity: CRITICAL
Suggested Fix
To correctly handle the error and prevent an app crash, wrap the code inside the
onPressevent handler with atry/catchblock. This will allow you to catch the exception and manage the application state or UI accordingly, without relying on the React Error Boundary for event-driven errors.Prompt for AI Agent