]> git.ipfire.org Git - collecty.git/commitdiff
plugins: Return None if file could not be read
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 1 Dec 2021 21:42:19 +0000 (21:42 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 1 Dec 2021 21:42:19 +0000 (21:42 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/collecty/plugins/base.py

index 561fa7b04c863754f05046a6091460eae05d8b44..9518ea1e2ec83420bf9d5b93e3be49f71878d8ba 100644 (file)
@@ -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):