Skip to content

Commit a5e0a9f

Browse files
committed
cppcheckdata: if 'import pathlib' fails then print a proper error message that explains how user can solve the problem.
1 parent 54478bd commit a5e0a9f

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

addons/cppcheckdata.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,25 @@
99
import argparse
1010
import json
1111
import os
12-
import pathlib
1312
import sys
13+
try:
14+
import pathlib
15+
except ImportError:
16+
message = "Failed to load pathlib. Upgrade python to 3.x or install pathlib with 'pip install pathlib'."
17+
error_id = 'pythonError'
18+
if '--cli' in sys.argv:
19+
msg = { 'file': '',
20+
'linenr': 0,
21+
'column': 0,
22+
'severity': 'error',
23+
'message': message,
24+
'addon': 'cppcheckdata',
25+
'errorId': error_id,
26+
'extra': ''}
27+
sys.stdout.write(json.dumps(msg) + '\n')
28+
else:
29+
sys.stderr.write('%s [%s]\n' % (message, error_id))
30+
sys.exit(1)
1431

1532
from xml.etree import ElementTree
1633
from fnmatch import fnmatch

0 commit comments

Comments
 (0)