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(setup): make the sync failure error screenshot- and copy-safe
Elian Doran1fc26a61fda0
diff --git a/apps/client/src/setup.css b/apps/client/src/setup.cssindex 1daa51c23c..e31b65dcb1 100644--- a/apps/client/src/setup.css+++ b/apps/client/src/setup.css@@ -508,6 +508,9 @@ body[dir=rtl] .slide-in-backward {white-space: pre-wrap;word-break: break-word;margin: 0 0 0.5rem;+ /* The error is meant to be copied into bug reports — opt back out of the+ app-wide `body { user-select: none }`. */+ user-select: text;}.admonition-body p {diff --git a/packages/trilium-core/src/services/sync.spec.ts b/packages/trilium-core/src/services/sync.spec.tsindex 165329e715..abdcf23f9d 100644--- a/packages/trilium-core/src/services/sync.spec.ts+++ b/packages/trilium-core/src/services/sync.spec.ts@@ -341,11 +341,16 @@ describe("sync service", () => {// is returned to whoever *triggered* the sync (often a fire-and-forget). The last// error must therefore be queryable so the wizard can leave its progress screen// instead of spinning forever (#10548).- it("records the failure message of the last sync attempt", async () => {- config.loginThrows = new Error("Request to PUT /api/sync/update failed, error: 401 Logged in session not found");+ it("records the failure message with the sync server's host redacted", async () => {+ // The setup wizard displays this message and users paste screenshots of it+ // into bug reports — the private host/port must not leak, while the path and+ // status (the diagnostically useful parts) stay visible.+ config.loginThrows = new Error(+ "Request to PUT https://trilium.private-domain.example:8443/api/sync/update?logMarkerId=x failed, error: 401 Logged in session not found"+ );await expect(runSync()).resolves.toMatchObject({ success: false });expect(syncService.getLastSyncError()).toBe(- "Request to PUT /api/sync/update failed, error: 401 Logged in session not found"+ "Request to PUT https://[redacted]/api/sync/update?logMarkerId=x failed, error: 401 Logged in session not found");});diff --git a/packages/trilium-core/src/services/sync.ts b/packages/trilium-core/src/services/sync.tsindex 0e914604bf..7d1fd09e7f 100644--- a/packages/trilium-core/src/services/sync.ts+++ b/packages/trilium-core/src/services/sync.ts@@ -123,7 +123,7 @@ async function sync() {ws.syncFailed();- lastSyncError = e.message;+ lastSyncError = redactUrlHosts(e.message);return {success: false,@@ -133,6 +133,17 @@ async function sync() {}}+/**+ * Replaces the host (and any port/credentials) of every URL in the message with+ * `[redacted]`, keeping the scheme and path. The recorded sync error is shown on the+ * setup wizard's failure screen, which users paste as screenshots into bug reports —+ * the private server host must not leak, while the endpoint path and status code (the+ * diagnostically useful parts) stay visible. The full message still goes to the log.+ */+function redactUrlHosts(message: string) {+ return message.replace(/(https?:\/\/)[^/\s]+/gi, "$1[redacted]");+}+/*** The failure message of the most recent sync attempt, or null when the last attempt* succeeded (or none ran yet). The sync result itself only reaches whoever *triggered*