Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give a warning if the user tries to open json file with viztracer #415

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/viztracer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import base64
import builtins
import configparser
import io
import json
import multiprocessing.util # type: ignore
import os
Expand Down Expand Up @@ -410,8 +411,11 @@ def run_command(self) -> VizProcedureResult:
search_result = self.search_file(file_name)
if not search_result:
return False, f"No such file as {file_name}"
if file_name.endswith(".json"):
return False, f"viztracer can't run json file, did you mean \"vizviewer {file_name}\"?"
file_name = search_result
with open(file_name, "rb") as f:

with io.open_code(file_name) as f:
code_string = f.read()
if options.magic_comment or options.log_var or options.log_number or options.log_attr or \
options.log_func_exec or options.log_exception or options.log_func_entry:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ def test_show_version(self):

def test_invalid_file(self):
self.template(["viztracer", "no_such_file.py"], success=False, expected_output_file=[])
self.template(["viztracer", "result_wrong.json"], script_name="result_wrong.json",
success=False, expected_output_file=[], expected_stdout="vizviewer result_wrong.json")

def test_rcfile(self):

Expand Down
Loading