mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	feat(startup): display migration errors using system modal
This commit is contained in:
		@@ -6,6 +6,7 @@ import { crash } from "./utils.js";
 | 
				
			|||||||
import resourceDir from "./resource_dir.js";
 | 
					import resourceDir from "./resource_dir.js";
 | 
				
			||||||
import appInfo from "./app_info.js";
 | 
					import appInfo from "./app_info.js";
 | 
				
			||||||
import cls from "./cls.js";
 | 
					import cls from "./cls.js";
 | 
				
			||||||
 | 
					import { t } from "i18next";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface MigrationInfo {
 | 
					interface MigrationInfo {
 | 
				
			||||||
    dbVersion: number;
 | 
					    dbVersion: number;
 | 
				
			||||||
@@ -18,9 +19,7 @@ async function migrate() {
 | 
				
			|||||||
    const currentDbVersion = getDbVersion();
 | 
					    const currentDbVersion = getDbVersion();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (currentDbVersion < 214) {
 | 
					    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(t("migration.old_version"));
 | 
				
			||||||
 | 
					 | 
				
			||||||
        await crash();
 | 
					 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -83,10 +82,7 @@ async function migrate() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                log.info(`Migration to version ${mig.dbVersion} has been successful.`);
 | 
					                log.info(`Migration to version ${mig.dbVersion} has been successful.`);
 | 
				
			||||||
            } catch (e: any) {
 | 
					            } catch (e: any) {
 | 
				
			||||||
                log.error(`error during migration to version ${mig.dbVersion}: ${e.stack}`);
 | 
					                crash(t("migration.error_message", { version: mig.dbVersion, stack: e.stack }));
 | 
				
			||||||
                log.error("migration failed, crashing hard"); // this is not very user-friendly :-/
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                crash();
 | 
					 | 
				
			||||||
                break; // crash() is sometimes async
 | 
					                break; // crash() is sometimes async
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -136,11 +132,7 @@ async function migrateIfNecessary() {
 | 
				
			|||||||
    const currentDbVersion = getDbVersion();
 | 
					    const currentDbVersion = getDbVersion();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (currentDbVersion > appInfo.dbVersion && process.env.TRILIUM_IGNORE_DB_VERSION !== "true") {
 | 
					    if (currentDbVersion > appInfo.dbVersion && process.env.TRILIUM_IGNORE_DB_VERSION !== "true") {
 | 
				
			||||||
        log.error(
 | 
					        await crash(t("migration.wrong_db_version", { version: currentDbVersion, targetVersion: appInfo.dbVersion }));
 | 
				
			||||||
            `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();
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!isDbUpToDate()) {
 | 
					    if (!isDbUpToDate()) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,6 +10,8 @@ import path from "path";
 | 
				
			|||||||
import { fileURLToPath } from "url";
 | 
					import { fileURLToPath } from "url";
 | 
				
			||||||
import { dirname, join } from "path";
 | 
					import { dirname, join } from "path";
 | 
				
			||||||
import type NoteMeta from "./meta/note_meta.js";
 | 
					import type NoteMeta from "./meta/note_meta.js";
 | 
				
			||||||
 | 
					import log from "./log.js";
 | 
				
			||||||
 | 
					import { t } from "i18next";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const randtoken = generator({ source: "crypto" });
 | 
					const randtoken = generator({ source: "crypto" });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -105,10 +107,13 @@ export function escapeRegExp(str: string) {
 | 
				
			|||||||
    return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
 | 
					    return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export async function crash() {
 | 
					export async function crash(message: string) {
 | 
				
			||||||
    if (isElectron) {
 | 
					    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 {
 | 
					    } else {
 | 
				
			||||||
 | 
					        log.error(message);
 | 
				
			||||||
        process.exit(1);
 | 
					        process.exit(1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -272,5 +272,13 @@
 | 
				
			|||||||
    "today": "Open today's journal note",
 | 
					    "today": "Open today's journal note",
 | 
				
			||||||
    "new-note": "New note",
 | 
					    "new-note": "New note",
 | 
				
			||||||
    "show-windows": "Show windows"
 | 
					    "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"
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -272,5 +272,13 @@
 | 
				
			|||||||
    "today": "Mergi la notița de astăzi",
 | 
					    "today": "Mergi la notița de astăzi",
 | 
				
			||||||
    "tooltip": "TriliumNext Notes",
 | 
					    "tooltip": "TriliumNext Notes",
 | 
				
			||||||
    "show-windows": "Afișează ferestrele"
 | 
					    "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"
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user