From 92992df7dfaaf2556dd68231b8130f5b7d101a02 Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 11 Feb 2026 13:56:42 +0100 Subject: [PATCH] test: ensure ragelogger resist to JSON.stringify throws --- src/settings/rageshake.test.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/settings/rageshake.test.ts diff --git a/src/settings/rageshake.test.ts b/src/settings/rageshake.test.ts new file mode 100644 index 00000000..9c3f1486 --- /dev/null +++ b/src/settings/rageshake.test.ts @@ -0,0 +1,34 @@ +/* +Copyright 2026 Element Creations Ltd. + +SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial +Please see LICENSE in the repository root for full details. +*/ + +import { expect, it } from "vitest"; + +import { init as initRageshake } from "./rageshake"; + +it("Logger should not crash if JSON.stringify fails", async () => { + // JSON.stringify can throw. We want to make sure that the logger can handle this gracefully. + await initRageshake(); + + const bigIntObj = { n: 1n }; + const notStringifiable = { + bigIntObj, + }; + // @ts-expect-error - we want to create an object that cannot be stringified + notStringifiable.foo = notStringifiable; // circular reference + + // ensure this cannot be stringified + expect(() => JSON.stringify(notStringifiable)).toThrow(); + + expect(() => + global.mx_rage_logger.log( + 1, + "test", + "This is a test message", + notStringifiable, + ), + ).not.toThrow(); +});