Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

add try/catch to handle errors

ammarahm-ed8f9c549376a0
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index af8f5f173..dc56aa719 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -53,12 +53,18 @@ const App = () => {
async function Initialize(colors = colors) {
let newColors = await getColorScheme(colors);
- let s = await MMKV.getStringAsync('settings');
+
+ let s;
+ try {
+ s = await MMKV.getStringAsync('settings');
+ } catch (e) {}
if (typeof s !== 'string') {
s = defaultState.settings;
s = JSON.stringify(s);
s.fontScale = 1;
+
await MMKV.setStringAsync('settings', s);
+
dispatch({type: ACTIONS.SETTINGS, s});
} else {
s = JSON.parse(s);
diff --git a/apps/mobile/src/common/common.js b/apps/mobile/src/common/common.js
index 6938e5856..2cd8ea33e 100755
--- a/apps/mobile/src/common/common.js
+++ b/apps/mobile/src/common/common.js
@@ -185,8 +185,14 @@ export function setColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {
}
export async function getColorScheme() {
- let accentColor = await MMKV.getStringAsync('accentColor');
- let t = await MMKV.getStringAsync('theme');
+ let accentColor;
+ try {
+ accentColor = await MMKV.getStringAsync('accentColor');
+ } catch (e) {}
+ let t;
+ try {
+ t = await MMKV.getStringAsync('theme');
+ } catch (e) {}
if (typeof accentColor !== 'string') {
MMKV.setStringAsync('accentColor', '#0560FF');
diff --git a/apps/mobile/src/utils/storage.js b/apps/mobile/src/utils/storage.js
index eb3584335..3eea98960 100644
--- a/apps/mobile/src/utils/storage.js
+++ b/apps/mobile/src/utils/storage.js
@@ -6,9 +6,17 @@ var Aes = NativeModules.Aes;
async function read(key, isArray = false) {
let data;
if (isArray) {
- data = await MMKV.getArrayAsync(key);
+ try {
+ data = await MMKV.getArrayAsync(key);
+ } catch (e) {
+ data = [];
+ }
} else {
- data = await MMKV.getMapAsync(key);
+ try {
+ data = await MMKV.getMapAsync(key);
+ } catch (e) {
+ data = null;
+ }
}
return isArray ? data.slice() : data;