From a5e0a9fe081e2ed9fe24cec064bc76f2b277b9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 22 Apr 2022 21:39:14 +0200 Subject: [PATCH] cppcheckdata: if 'import pathlib' fails then print a proper error message that explains how user can solve the problem. --- addons/cppcheckdata.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index cdffe62a5..16a1414a9 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -9,8 +9,25 @@ License: No restrictions, use this as you need. import argparse import json import os -import pathlib import sys +try: + import pathlib +except ImportError: + message = "Failed to load pathlib. Upgrade python to 3.x or install pathlib with 'pip install pathlib'." + error_id = 'pythonError' + if '--cli' in sys.argv: + msg = { 'file': '', + 'linenr': 0, + 'column': 0, + 'severity': 'error', + 'message': message, + 'addon': 'cppcheckdata', + 'errorId': error_id, + 'extra': ''} + sys.stdout.write(json.dumps(msg) + '\n') + else: + sys.stderr.write('%s [%s]\n' % (message, error_id)) + sys.exit(1) from xml.etree import ElementTree from fnmatch import fnmatch