Skip to content

Commit

Permalink
bugfix: core: text-browsers causing ZT to freeze.
Browse files Browse the repository at this point in the history
Temporarily unsetting TERM environ so text-browsers aren't detected.

This results in an exception which displays an error for text-browsers.
  • Loading branch information
Sushmey committed Apr 15, 2024
1 parent a2e616e commit 6b50465
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/core/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ def test_open_in_browser_success(
) -> None:
# Set DISPLAY environ to be able to run test in CI
os.environ["DISPLAY"] = ":0"
# Set TERM environ to be able to check text-browsers
os.environ["TERM"] = "xterm-256color"
mocked_report_success = mocker.patch(MODULE + ".Controller.report_success")
mock_get = mocker.patch(MODULE + ".webbrowser.get")
mock_open = mock_get.return_value.open
Expand All @@ -447,6 +449,7 @@ def test_open_in_browser_fail__no_browser_controller(
self, mocker: MockerFixture, controller: Controller
) -> None:
os.environ["DISPLAY"] = ":0"
os.environ["TERM"] = "xterm-256color"
error = "No runnable browser found"
mocked_report_error = mocker.patch(MODULE + ".Controller.report_error")
mocker.patch(MODULE + ".webbrowser.get").side_effect = webbrowser.Error(error)
Expand Down
4 changes: 4 additions & 0 deletions zulipterminal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ def open_in_browser(self, url: str) -> None:
try:
# Checks for a runnable browser in the system and returns
# its browser controller, if found, else reports an error
term = os.environ.get("TERM") # Saving the original value
del os.environ["TERM"] # Temporarily deleting variable
browser_controller = webbrowser.get()
# Suppress stdout and stderr when opening browser
with suppress_output():
Expand All @@ -424,6 +426,8 @@ def open_in_browser(self, url: str) -> None:
[f"The link was successfully opened using {browser_name}"]
)
except webbrowser.Error as e:
if isinstance(term, str):
os.environ["TERM"] = term # resetting
# Set a footer text if no runnable browser is located
self.report_error([f"ERROR: {e}"])

Expand Down

0 comments on commit 6b50465

Please sign in to comment.