Skip to content

Commit

Permalink
Fixed exception handling for vizviewer
Browse files Browse the repository at this point in the history
  • Loading branch information
gaogaotiantian committed Jul 17, 2023
1 parent 67219a9 commit 1ae9c50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/viztracer/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import socketserver
import subprocess
import sys
import traceback
import threading
import time
import urllib.parse
Expand Down Expand Up @@ -298,9 +299,14 @@ def __init__(
super().__init__(daemon=True)

def run(self) -> None:
self.retcode = self.view()
# If it returns from view(), also set ready
self.ready.set()
try:
self.retcode = self.view()
except Exception as e:
self.retcode = 1
traceback.print_exception(e)
finally:
# If it returns from view(), also set ready
self.ready.set()

def view(self) -> int:
# Get file data
Expand Down
3 changes: 3 additions & 0 deletions tests/test_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ def test_directory_max_port(self):
finally:
shutil.rmtree(tmp_dir)

def test_exception(self):
self.template(["vizviewer", "--port", "-3", "cmdline_test.json"], success=False, expected_output_file=None)

def test_invalid(self):
self.template(["vizviewer", "do_not_exist.json"], success=False, expected_output_file=None)
self.template(["vizviewer", "README.md"], success=False, expected_output_file=None)
Expand Down

0 comments on commit 1ae9c50

Please sign in to comment.