Skip to content

Commit 8d338f5

Browse files
committed
refactor: core: Change report_error argument type to list.
Change argument type of report_error from text: str to text: List[Union[str, Tuple[Literal["footer_contrast"], str]]].
1 parent 6f3631f commit 8d338f5

File tree

10 files changed

+33
-22
lines changed

10 files changed

+33
-22
lines changed

tests/core/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ def test_open_in_browser_fail__no_browser_controller(
430430

431431
controller.open_in_browser("https://chat.zulip.org/#narrow/stream/test")
432432

433-
mocked_report_error.assert_called_once_with(f"ERROR: {error}")
433+
mocked_report_error.assert_called_once_with([f"ERROR: {error}"])
434434

435435
def test_main(self, mocker: MockerFixture, controller: Controller) -> None:
436436
controller.view.palette = {"default": "theme_properties"}

tests/helper/test_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def test_display_error_if_present(
327327
display_error_if_present(response, controller)
328328

329329
if footer_updated:
330-
report_error.assert_called_once_with(response["msg"])
330+
report_error.assert_called_once_with([response["msg"]])
331331
else:
332332
report_error.assert_not_called()
333333

tests/ui/test_ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ def test_keypress_OPEN_DRAFT(
459459
view.middle_column.set_focus.assert_called_once_with("footer")
460460
else:
461461
view.controller.report_error.assert_called_once_with(
462-
"No draft message was saved in this session."
462+
["No draft message was saved in this session."]
463463
)
464464

465465
@pytest.mark.parametrize("key", keys_for_command("SEARCH_PEOPLE"))

tests/ui/test_ui_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2582,7 +2582,7 @@ def test_keypress_EDIT_MESSAGE(
25822582
[expect_footer_text[message_type]]
25832583
)
25842584
else:
2585-
report_error.assert_called_once_with(expect_footer_text[message_type])
2585+
report_error.assert_called_once_with([expect_footer_text[message_type]])
25862586

25872587
@pytest.mark.parametrize(
25882588
"raw_html, expected_content",

tests/ui_tools/test_boxes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def test_footer_notification_on_invalid_recipients(
362362
size = widget_size(write_box)
363363
write_box.keypress(size, key)
364364

365-
self.view.controller.report_error.assert_called_once_with(expected_lines)
365+
self.view.controller.report_error.assert_called_once_with([expected_lines])
366366
# If there are invalid recipients, we expect the focus
367367
# to remain in the to_write_box.
368368
assert write_box.focus_position == write_box.FOCUS_CONTAINER_HEADER

zulipterminal/core.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,9 @@ def open_in_browser(self, url: str) -> None:
400400
and os.environ.get("TERM")
401401
):
402402
self.report_error(
403-
"No DISPLAY environment variable specified. This could "
404-
"likely mean the ZT host is running without a GUI."
403+
[
404+
"No DISPLAY environment variable specified. This could likely mean the ZT host is running without a GUI."
405+
]
405406
)
406407
return
407408
try:
@@ -418,7 +419,7 @@ def open_in_browser(self, url: str) -> None:
418419
)
419420
except webbrowser.Error as e:
420421
# Set a footer text if no runnable browser is located
421-
self.report_error(f"ERROR: {e}")
422+
self.report_error([f"ERROR: {e}"])
422423

423424
@asynch
424425
def show_typing_notification(self) -> None:
@@ -439,7 +440,11 @@ def show_typing_notification(self) -> None:
439440
self.is_typing_notification_in_progress = False
440441
self.view.set_footer_text()
441442

442-
def report_error(self, text: str, duration: int = 3) -> None:
443+
def report_error(
444+
self,
445+
text: List[Union[str, Tuple[Literal["footer_contrast"], str]]],
446+
duration: int = 3,
447+
) -> None:
443448
"""
444449
Helper to show an error message in footer
445450
"""

zulipterminal/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ def canonicalize_color(color: str) -> str:
639639

640640
def display_error_if_present(response: Dict[str, Any], controller: Any) -> None:
641641
if response["result"] == "error" and hasattr(controller, "view"):
642-
controller.report_error(response["msg"])
642+
controller.report_error([response["msg"]])
643643

644644

645645
def check_narrow_and_notify(

zulipterminal/ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def keypress(self, size: urwid_Box, key: str) -> Optional[str]:
296296
self.middle_column.set_focus("footer")
297297
else:
298298
self.controller.report_error(
299-
"No draft message was saved in this session."
299+
["No draft message was saved in this session."]
300300
)
301301
return key
302302
elif is_command_key("ABOUT", key):

zulipterminal/ui_tools/boxes.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def _tidy_valid_recipients_and_notify_invalid_ones(
329329
),
330330
" to autocomplete.",
331331
]
332-
self.view.controller.report_error(invalid_recipients_error)
332+
self.view.controller.report_error([invalid_recipients_error])
333333
return False
334334

335335
return True
@@ -765,7 +765,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
765765
)
766766
else:
767767
self.view.controller.report_error(
768-
"Cannot send message without specifying recipients."
768+
["Cannot send message without specifying recipients."]
769769
)
770770
success = None
771771
if success:
@@ -830,7 +830,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
830830
primary_key_for_command("AUTOCOMPLETE_REVERSE"),
831831
)
832832
)
833-
self.view.controller.report_error(invalid_stream_error)
833+
self.view.controller.report_error([invalid_stream_error])
834834
return key
835835
user_ids = self.model.get_other_subscribers_in_stream(
836836
stream_name=stream_name
@@ -1844,17 +1844,20 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
18441844
):
18451845
if self.message["type"] == "stream":
18461846
self.model.controller.report_error(
1847-
" You can't edit messages sent by other users that"
1848-
" already have a topic."
1847+
[
1848+
" You can't edit messages sent by other users that already have a topic."
1849+
]
18491850
)
18501851
else:
18511852
self.model.controller.report_error(
1852-
" You can't edit private messages sent by other users."
1853+
[" You can't edit private messages sent by other users."]
18531854
)
18541855
return key
18551856
# Check if editing is allowed in the realm
18561857
elif not self.model.initial_data["realm_allow_message_editing"]:
1857-
self.model.controller.report_error(" Editing sent message is disabled.")
1858+
self.model.controller.report_error(
1859+
[" Editing sent message is disabled."]
1860+
)
18581861
return key
18591862
# Check if message is still editable, i.e. within
18601863
# the time limit. A limit of 0 signifies no limit
@@ -1870,7 +1873,9 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
18701873
if time_since_msg_sent >= edit_time_limit:
18711874
if self.message["type"] == "private":
18721875
self.model.controller.report_error(
1873-
" Time Limit for editing the message has been exceeded."
1876+
[
1877+
" Time Limit for editing the message has been exceeded."
1878+
]
18741879
)
18751880
return key
18761881
elif self.message["type"] == "stream":
@@ -1891,8 +1896,9 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
18911896
msg_body_edit_enabled = False
18921897
else:
18931898
self.model.controller.report_error(
1894-
" You can't edit messages sent by other users that"
1895-
" already have a topic."
1899+
[
1900+
" You can't edit messages sent by other users that already have a topic."
1901+
]
18961902
)
18971903
return key
18981904
else:

zulipterminal/ui_tools/buttons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ def handle_narrow_link(self) -> None:
607607
error = self._validate_narrow_link(parsed_link)
608608

609609
if error:
610-
self.controller.report_error(f" {error}")
610+
self.controller.report_error([f" {error}"])
611611
else:
612612
self._switch_narrow_to(parsed_link)
613613

0 commit comments

Comments
 (0)