From 7a24d844c5cd936ea2ec73da7cd62864bf450e56 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Wed, 15 Nov 2023 11:46:33 +1300 Subject: [PATCH] Add fatal error message if database fails to initialize This will help with debugging if the user can directly provide what error occurred. --- App.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/App.tsx b/App.tsx index 3e49a5b..0267f56 100644 --- a/App.tsx +++ b/App.tsx @@ -4,11 +4,12 @@ import { NavigationContainer, } from "@react-navigation/native"; import React, { useEffect, useMemo, useState } from "react"; -import { useColorScheme } from "react-native"; +import { View, useColorScheme } from "react-native"; import { MD3DarkTheme as PaperDarkTheme, MD3LightTheme as PaperDefaultTheme, Provider as PaperProvider, + Text, } from "react-native-paper"; import MaterialIcon from "react-native-vector-icons/MaterialCommunityIcons"; import AppSnack from "./AppSnack"; @@ -16,6 +17,7 @@ import AppStack from "./AppStack"; import { AppDataSource } from "./data-source"; import { settingsRepo } from "./db"; import { ThemeContext } from "./use-theme"; +import { MARGIN } from "./constants"; export const CombinedDefaultTheme = { ...NavigationDefaultTheme, @@ -45,10 +47,12 @@ const App = () => { lightColor: CombinedDefaultTheme.colors.primary, darkColor: CombinedDarkTheme.colors.primary, }); + const [error, setError] = useState(""); useEffect(() => { (async () => { - if (!AppDataSource.isInitialized) await AppDataSource.initialize(); + if (!AppDataSource.isInitialized) + await AppDataSource.initialize().catch((e) => setError(e.toString())); const gotSettings = await settingsRepo.findOne({ where: {} }); console.log({ gotSettings }); setAppSettings({ @@ -88,6 +92,17 @@ const App = () => { settings={{ icon: (props) => }} > + {error && ( + + + Database failed to initialize: {error} + + + )} {appSettings.startup !== undefined && (