Skip to content

Commit 112a5c4

Browse files
committed
pdf preview: raise exception on process call error
1 parent c412bbf commit 112a5c4

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

tuttle/os_functions.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,21 @@ def open_application(app_name):
1818

1919
def preview_pdf(file_path):
2020
"""Preview a PDF file."""
21-
if not Path(file_path).exists():
22-
raise FileNotFoundError(f"File not found: {file_path}")
23-
if platform.system() == "Darwin":
24-
os.system("qlmanage -p {}".format(file_path))
25-
elif platform.system() == "Windows":
26-
os.startfile(file_path)
27-
elif platform.system() == "Linux":
28-
os.system("xdg-open {}".format(file_path))
29-
else:
30-
print("Sorry, your platform is not supported.")
21+
try:
22+
if not Path(file_path).exists():
23+
raise FileNotFoundError(f"File not found: {file_path}")
24+
if platform.system() == "Darwin":
25+
subprocess.check_call(["qlmanage", "-p", file_path])
26+
elif platform.system() == "Windows":
27+
os.startfile(file_path)
28+
elif platform.system() == "Linux":
29+
subprocess.check_call(["xdg-open", file_path])
30+
else:
31+
raise RuntimeError("Sorry, your platform is not supported.")
32+
except subprocess.CalledProcessError as err:
33+
raise RuntimeError(
34+
f"Error occurred while opening the PDF file. Return code: {err.returncode}. Error: {err.output}"
35+
)
3136

3237

3338
def open_folder(folder_path):

0 commit comments

Comments
 (0)