From 4f02795830072ea8fcc3ae4bb10ce1826585f95f Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 8 Mar 2019 17:36:01 -0800 Subject: [PATCH] home: Fix parsing bug for initial narrows. There's more we'll want to do here, but this at least avoids error emails when users attempt to misuse this interface. --- zerver/tests/test_home.py | 4 ++-- zerver/views/home.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py index 38ceca87b4..4ac3f004b3 100644 --- a/zerver/tests/test_home.py +++ b/zerver/tests/test_home.py @@ -404,10 +404,10 @@ class HomeTest(ZulipTestCase): def test_bad_narrow(self) -> None: email = self.example_email("hamlet") self.login(email) - with patch('logging.exception') as mock: + with patch('logging.warning') as mock: result = self._get_home_page(stream='Invalid Stream') mock.assert_called_once() - self.assertEqual(mock.call_args_list[0][0][0], "Narrow parsing exception") + self.assertEqual(mock.call_args_list[0][0][0], "Invalid narrow requested, ignoring") self._sanity_check(result) def test_bad_pointer(self) -> None: diff --git a/zerver/views/home.py b/zerver/views/home.py index c720910f31..330edfbbb7 100644 --- a/zerver/views/home.py +++ b/zerver/views/home.py @@ -117,12 +117,13 @@ def home_real(request: HttpRequest) -> HttpResponse: narrow_topic = request.GET.get("topic") if request.GET.get("stream"): try: + # TODO: We should support stream IDs and PMs here as well. narrow_stream_name = request.GET.get("stream") (narrow_stream, ignored_rec, ignored_sub) = access_stream_by_name( user_profile, narrow_stream_name) narrow = [["stream", narrow_stream.name]] except Exception: - logging.exception("Narrow parsing exception", extra=dict(request=request)) + logging.warning("Invalid narrow requested, ignoring", extra=dict(request=request)) if narrow_stream is not None and narrow_topic is not None: narrow.append(["topic", narrow_topic])