From acf9aa8b419bbd85df135ead4f1450516ab9a777 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 9 Apr 2026 17:52:48 +0300 Subject: [PATCH] fix(core): issues with some utils --- .../trilium-core/src/services/utils/index.spec.ts | 11 +++++++++-- packages/trilium-core/src/services/utils/index.ts | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/trilium-core/src/services/utils/index.spec.ts b/packages/trilium-core/src/services/utils/index.spec.ts index da3991cb2a..398cad7161 100644 --- a/packages/trilium-core/src/services/utils/index.spec.ts +++ b/packages/trilium-core/src/services/utils/index.spec.ts @@ -530,8 +530,15 @@ describe("#safeExtractMessageAndStackFromError", () => { expect(actual[1]).not.toBeUndefined(); }); - it("should use the fallback 'Unknown Error' message, if it gets passed anything else than an instance of an Error", () => { - const testNonError = "this is not an instance of an Error, but JS technically allows us to throw this anyways"; + it("should pass a thrown string through as the message, with no stack", () => { + const testString = "this is not an instance of an Error, but JS technically allows us to throw this anyways"; + const actual = utils.safeExtractMessageAndStackFromError(testString); + expect(actual[0]).toBe(testString); + expect(actual[1]).toBeUndefined(); + }); + + it("should use the fallback 'Unknown Error' message, if it gets passed something that is neither an Error nor a string", () => { + const testNonError = { not: "an error" }; const actual = utils.safeExtractMessageAndStackFromError(testNonError); expect(actual[0]).toBe("Unknown Error"); expect(actual[1]).toBeUndefined(); diff --git a/packages/trilium-core/src/services/utils/index.ts b/packages/trilium-core/src/services/utils/index.ts index 3672b683ef..0869e28bce 100644 --- a/packages/trilium-core/src/services/utils/index.ts +++ b/packages/trilium-core/src/services/utils/index.ts @@ -211,7 +211,7 @@ export const escapeHtml = escape; export const unescapeHtml = unescape; export function randomSecureToken(bytes = 32) { - return encodeBase64(getCrypto().randomBytes(32)); + return encodeBase64(getCrypto().randomBytes(bytes)); } export function safeExtractMessageAndStackFromError(err: unknown): [errMessage: string, errStack: string | undefined] {