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
fix(sync): show why the sync server is unreachable
Elian Doranc0a329af84fb
diff --git a/packages/trilium-core/src/services/sync.spec.ts b/packages/trilium-core/src/services/sync.spec.tsindex 31215baa7b..19d8f0bdc0 100644--- a/packages/trilium-core/src/services/sync.spec.ts+++ b/packages/trilium-core/src/services/sync.spec.ts@@ -453,9 +453,15 @@ describe("sync service", () => {await expect(runSync()).resolves.toEqual({ success: false, message: "Got no response." });});- it("reports a connection failure without a stack-trace message", async () => {- config.loginThrows = new Error("connect ECONNREFUSED 127.0.0.1:8080");- await expect(runSync()).resolves.toEqual({ success: false, message: "No connection to sync server." });+ it("reports a connection failure together with its cause", async () => {+ config.loginThrows = new Error(+ "Request to POST https://sync.example:8443/api/login/sync failed, error: connect ECONNREFUSED 10.0.0.5:8443"+ );+ await expect(runSync()).resolves.toEqual({+ success: false,+ message: "No connection to sync server: Request to POST https://sync.example:8443/api/login/sync failed, "+ + "error: connect ECONNREFUSED 10.0.0.5:8443"+ });});it("reports other sync errors with their message", async () => {@@ -481,10 +487,14 @@ describe("sync service", () => {);});- it("records connection failures with the user-facing message", async () => {- config.loginThrows = new Error("connect ECONNREFUSED 127.0.0.1:8080");+ it("records connection failures with their cause and the host redacted", async () => {+ config.loginThrows = new Error(+ "Request to POST https://sync.example:8443/api/login/sync failed, error: 502 Bad Gateway"+ );await expect(runSync()).resolves.toMatchObject({ success: false });- expect(syncService.getLastSyncError()).toBe("No connection to sync server.");+ expect(syncService.getLastSyncError()).toBe(+ "No connection to sync server: Request to POST https://[redacted]/api/login/sync failed, error: 502 Bad Gateway"+ );});it("clears the recorded error once a subsequent sync succeeds", async () => {diff --git a/packages/trilium-core/src/services/sync.ts b/packages/trilium-core/src/services/sync.tsindex e4e75ea333..e50bc7a018 100644--- a/packages/trilium-core/src/services/sync.ts+++ b/packages/trilium-core/src/services/sync.ts@@ -165,13 +165,15 @@ async function sync() {) {ws.syncFailed();- log.info("No connection to sync server.");+ const message = `No connection to sync server: ${e.message}`;- lastSyncError = "No connection to sync server.";+ log.info(message);++ lastSyncError = redactUrlHosts(message);return {success: false,- message: lastSyncError+ message};}log.info(`Sync failed: '${e.message}', stack: ${e.stack}`);