fix(core): issues with some utils

This commit is contained in:
Elian Doran
2026-04-09 17:52:48 +03:00
parent 6e0e7847e4
commit acf9aa8b41
2 changed files with 10 additions and 3 deletions

View File

@@ -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();

View File

@@ -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] {