Skip to content

Build your personal knowledge base with Trilium Notes

fix(core): issues with some utils

Elian Doranacf9aa8b419b
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] {