From: Michael Tremer Date: Wed, 1 Dec 2021 21:42:19 +0000 (+0000) Subject: plugins: Return None if file could not be read X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6a8cbe5e1151e1f1fe3fcb54e16c23bb71222043;p=collecty.git plugins: Return None if file could not be read Signed-off-by: Michael Tremer --- diff --git a/src/collecty/plugins/base.py b/src/collecty/plugins/base.py index 561fa7b..9518ea1 100644 --- a/src/collecty/plugins/base.py +++ b/src/collecty/plugins/base.py @@ -448,8 +448,11 @@ class Object(object): """ filename = os.path.join(*args) - with open(filename) as f: - value = f.read() + try: + with open(filename) as f: + value = f.read() + except FileNotFoundError as e: + return None # Strip any excess whitespace if strip: @@ -465,7 +468,7 @@ class Object(object): try: return int(value) - except ValueError: + except (TypeError, ValueError): return None def read_proc_stat(self):