From 7bff14932575f2d15ad103b2f57d3e193a1cb29e Mon Sep 17 00:00:00 2001 From: evykassirer Date: Tue, 24 Sep 2024 11:26:27 -0700 Subject: [PATCH] filter: Fix bug where invalid stream name could throw an error. --- web/src/filter.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/web/src/filter.ts b/web/src/filter.ts index 7b4965e707..f196975ae0 100644 --- a/web/src/filter.ts +++ b/web/src/filter.ts @@ -724,14 +724,17 @@ export class Filter { Filter.canonicalize_operator(term.operator) === expected && !term.negated; if (is(terms[0], "channel") && is(terms[1], "topic")) { - const channel = stream_data.get_valid_sub_by_id_string(terms[0].operand).name; - const topic = terms[1].operand; - parts.push({ - type: "channel_topic", - channel, - topic, - }); - terms = terms.slice(2); + // `channel` might be undefined if it's coming from a text query + const channel = stream_data.get_sub_by_id_string(terms[0].operand)?.name; + if (channel) { + const topic = terms[1].operand; + parts.push({ + type: "channel_topic", + channel, + topic, + }); + terms = terms.slice(2); + } } }