Skip to content

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

mobile: show user-friendly error for invalid theme file upload

kashaf-ansari-dev70147d4332b6
diff --git a/apps/mobile/app/screens/settings/theme-selector.tsx b/apps/mobile/app/screens/settings/theme-selector.tsx
index 073adbd02..8e42c6ed7 100644
--- a/apps/mobile/app/screens/settings/theme-selector.tsx
+++ b/apps/mobile/app/screens/settings/theme-selector.tsx
@@ -441,7 +441,17 @@ function ThemeSelector() {
ReactNativeBlobUtil.fs
.unlink(themeJsonCopiedPath)
.catch(() => {});
- const json = JSON.parse(themeJson);
+ let json;
+ try {
+ json = JSON.parse(themeJson);
+ } catch (e) {
+ ToastManager.show({
+ heading: strings.invalidThemeFileFormat(),
+ type: "error",
+ context: "global"
+ });
+ return;
+ }
const result = validateTheme(json);
if (result.error) {
ToastManager.error(new Error(result.error));
diff --git a/packages/intl/locale/en.po b/packages/intl/locale/en.po
index 842f61e8a..bad0875a9 100644
--- a/packages/intl/locale/en.po
+++ b/packages/intl/locale/en.po
@@ -7273,6 +7273,10 @@ msgstr "We are creating a backup of your data. Please wait..."
msgid "We are sorry, it seems that the app crashed due to an error. You can submit a bug report below so we can fix this asap."
msgstr "We are sorry, it seems that the app crashed due to an error. You can submit a bug report below so we can fix this asap."
+#: src/strings.ts:2700
+msgid "We couldn't load this theme. Please make sure the file is a valid theme export."
+msgstr "We couldn't load this theme. Please make sure the file is a valid theme export."
+
#: src/strings.ts:1390
msgid "We have sent you an email confirmation link. Please check your email inbox. If you cannot find the email, check your spam folder."
msgstr "We have sent you an email confirmation link. Please check your email inbox. If you cannot find the email, check your spam folder."
diff --git a/packages/intl/locale/pseudo-LOCALE.po b/packages/intl/locale/pseudo-LOCALE.po
index 103ffefb4..9202bdeae 100644
--- a/packages/intl/locale/pseudo-LOCALE.po
+++ b/packages/intl/locale/pseudo-LOCALE.po
@@ -7223,6 +7223,10 @@ msgstr ""
msgid "We are sorry, it seems that the app crashed due to an error. You can submit a bug report below so we can fix this asap."
msgstr ""
+#: src/strings.ts:2700
+msgid "We couldn't load this theme. Please make sure the file is a valid theme export."
+msgstr ""
+
#: src/strings.ts:1390
msgid "We have sent you an email confirmation link. Please check your email inbox. If you cannot find the email, check your spam folder."
msgstr ""
diff --git a/packages/intl/src/strings.ts b/packages/intl/src/strings.ts
index 79024af1b..30d9bf16d 100644
--- a/packages/intl/src/strings.ts
+++ b/packages/intl/src/strings.ts
@@ -2695,5 +2695,7 @@ Continue without attachments?`,
t`Creation date cannot be after last edited date`,
noteDuplicated: () => t`Note duplicated`,
maximumReminderDate: (maxDate: string) =>
- t`Maximum reminder date is ${maxDate}`
+ t`Maximum reminder date is ${maxDate}`,
+ invalidThemeFileFormat: () =>
+ t`We couldn't load this theme. Please make sure the file is a valid theme export.`
};