Skip to content

Commit 01c49a2

Browse files
committed
logging and better exception handling
1 parent 30e0955 commit 01c49a2

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

servicex_analysis_utils/cli.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
import json
44
import os
5+
import logging
56
from .file_peeking import get_structure
67

78

@@ -27,27 +28,20 @@ def run_from_command():
2728
dataset_file = args.dataset[0]
2829

2930
if not os.path.isfile(dataset_file):
30-
print(
31-
f"\033[91mError: JSON file '{dataset_file}' not found.\033[0m",
32-
file=sys.stderr,
33-
)
31+
logging.error(f"Error: JSON file '{dataset_file}' not found.")
3432
sys.exit(1)
3533

3634
try:
3735
with open(dataset_file, "r") as f:
3836
dataset = json.load(f)
3937

4038
if not isinstance(dataset, dict):
41-
print(
42-
f"\033[91mError: The JSON file must contain a dictionary.\033[0m",
43-
file=sys.stderr,
44-
)
39+
logging.error(f"Error: The JSON file must contain a dictionary.")
4540
sys.exit(1)
4641

4742
except json.JSONDecodeError:
48-
print(
49-
f"\033[91mError: '{dataset_file}' is not a valid JSON file.\033[0m",
50-
file=sys.stderr,
43+
logging.error(
44+
f"Error: '{dataset_file}' is not a valid JSON file.", exc_info=True
5145
)
5246
sys.exit(1)
5347

0 commit comments

Comments
 (0)