From 55793cb4d540973cd7c994d144be1f729916542d Mon Sep 17 00:00:00 2001 From: Zixuan James Li Date: Sun, 20 Nov 2022 22:56:36 -0800 Subject: [PATCH] util: Stringify possibly undefined values. This avoids "@typescript-eslint/restrict-template-expressions" when we convert util.js to util.ts. Note that prettier would otherwise split the first template literal expression in half if we don't start a newline. Signed-off-by: Zixuan James Li --- frontend_tests/node_tests/drafts.js | 2 +- static/js/util.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/frontend_tests/node_tests/drafts.js b/frontend_tests/node_tests/drafts.js index d44b7bacae..f9e9d9bad7 100644 --- a/frontend_tests/node_tests/drafts.js +++ b/frontend_tests/node_tests/drafts.js @@ -413,7 +413,7 @@ test("catch_buggy_draft_error", () => { // An error is logged but the draft isn't fixed in this codepath. blueslip.expect( "error", - "Cannot compare strings; at least one value is undefined: undefined, old_topic", + "Cannot compare strings; at least one value is undefined: (undefined), old_topic", ); drafts.rename_stream_recipient( stream_B.stream_id, diff --git a/static/js/util.js b/static/js/util.js index f20aad4bc5..fe5a722d78 100644 --- a/static/js/util.js +++ b/static/js/util.js @@ -41,7 +41,10 @@ export function lower_bound(array, value, less) { export const lower_same = function lower_same(a, b) { if (a === undefined || b === undefined) { - blueslip.error(`Cannot compare strings; at least one value is undefined: ${a}, ${b}`); + blueslip.error( + `Cannot compare strings; at least one value is undefined: \ +${a ?? "(undefined)"}, ${b ?? "(undefined)"}`, + ); return false; } return a.toLowerCase() === b.toLowerCase();