Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(startup): display migration errors using system modal
Elian Doran1c118f2aa9b8
diff --git a/src/services/migration.ts b/src/services/migration.tsindex 08b07f121f..f8cbfbc223 100644--- a/src/services/migration.ts+++ b/src/services/migration.ts@@ -6,6 +6,7 @@ import { crash } from "./utils.js";import resourceDir from "./resource_dir.js";import appInfo from "./app_info.js";import cls from "./cls.js";+import { t } from "i18next";interface MigrationInfo {dbVersion: number;@@ -18,9 +19,7 @@ async function migrate() {const currentDbVersion = getDbVersion();if (currentDbVersion < 214) {- log.error("Direct migration from your current version is not supported. Please upgrade to the latest v0.60.4 first and only then to this version.");-- await crash();+ await crash(t("migration.old_version"));return;}@@ -83,10 +82,7 @@ async function migrate() {log.info(`Migration to version ${mig.dbVersion} has been successful.`);} catch (e: any) {- log.error(`error during migration to version ${mig.dbVersion}: ${e.stack}`);- log.error("migration failed, crashing hard"); // this is not very user-friendly :-/-- crash();+ crash(t("migration.error_message", { version: mig.dbVersion, stack: e.stack }));break; // crash() is sometimes async}}@@ -136,11 +132,7 @@ async function migrateIfNecessary() {const currentDbVersion = getDbVersion();if (currentDbVersion > appInfo.dbVersion && process.env.TRILIUM_IGNORE_DB_VERSION !== "true") {- log.error(- `Current DB version ${currentDbVersion} is newer than the current DB version ${appInfo.dbVersion}, which means that it was created by a newer and incompatible version of Trilium. Upgrade to the latest version of Trilium to resolve this issue.`- );-- await crash();+ await crash(t("migration.wrong_db_version", { version: currentDbVersion, targetVersion: appInfo.dbVersion }));}if (!isDbUpToDate()) {diff --git a/src/services/utils.ts b/src/services/utils.tsindex 289e1af6bb..0da27c3d63 100644--- a/src/services/utils.ts+++ b/src/services/utils.ts@@ -10,6 +10,8 @@ import path from "path";import { fileURLToPath } from "url";import { dirname, join } from "path";import type NoteMeta from "./meta/note_meta.js";+import log from "./log.js";+import { t } from "i18next";const randtoken = generator({ source: "crypto" });@@ -105,10 +107,13 @@ export function escapeRegExp(str: string) {return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");}-export async function crash() {+export async function crash(message: string) {if (isElectron) {- (await import("electron")).app.exit(1);+ const electron = await import("electron");+ electron.dialog.showErrorBox(t("modals.error_title"), message);+ electron.app.exit(1);} else {+ log.error(message);process.exit(1);}}diff --git a/translations/en/server.json b/translations/en/server.jsonindex 49e08bb998..de60907cb3 100644--- a/translations/en/server.json+++ b/translations/en/server.json@@ -272,5 +272,13 @@"today": "Open today's journal note","new-note": "New note","show-windows": "Show windows"+ },+ "migration": {+ "old_version": "Direct migration from your current version is not supported. Please upgrade to the latest v0.60.4 first and only then to this version.",+ "error_message": "Error during migration to version {{version}}: {{stack}}",+ "wrong_db_version": "Current DB version {{version}} is newer than the current DB version {{targetVersion}}, which means that it was created by a newer and incompatible version of Trilium. Upgrade to the latest version of Trilium to resolve this issue."+ },+ "modals": {+ "error_title": "Error"}}diff --git a/translations/ro/server.json b/translations/ro/server.jsonindex ebf99082e2..0023c0c863 100644--- a/translations/ro/server.json+++ b/translations/ro/server.json@@ -272,5 +272,13 @@"today": "Mergi la notița de astăzi","tooltip": "TriliumNext Notes","show-windows": "Afișează ferestrele"+ },+ "migration": {+ "error_message": "Eroare la migrarea către versiunea {{version}}: {{stack}}",+ "old_version": "Nu se poate migra la ultima versiune direct de la versiunea dvs. Actualizați mai întâi la versiunea v0.60.4 și ulterior la această versiune.",+ "wrong_db_version": "Versiunea actuală a bazei de date ({{version}}) este mai nouă decât versiunea de bază de date suportată de aplicație ({{targetVersion}}), ceea ce înseamnă că a fost creată de către o versiune mai nouă de Trilium. Actualizați aplicația la ultima versiune pentru a putea continua."+ },+ "modals": {+ "error_title": "Eroare"}}