From ed61eab13a0bfc6e0f81b733ba1c4f8a7549cb43 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Wed, 17 Feb 2021 15:10:12 +0100 Subject: [PATCH] Plugin tor_: fix "tor_countries" in case of missing cache location Closes: #1176 --- plugins/tor/tor_ | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/plugins/tor/tor_ b/plugins/tor/tor_ index 3bf522a4..701e211d 100755 --- a/plugins/tor/tor_ +++ b/plugins/tor/tor_ @@ -309,15 +309,16 @@ class TorCountries(TorPlugin): def fetch(self): """Generate metrics""" - + # Fallback if cache_dir_name is not set, unreadable or any other error + countries_num = self.top_countries() # If possible, read cached data instead of doing the processing twice - try: - with open(self.cache_dir_name) as f: - countries_num = json.load(f) - except (IOError, ValueError): - # Fallback if cache_dir_name is not set, unreadable or any other - # error - countries_num = self.top_countries() + if self.cache_dir_name: + try: + with open(self.cache_dir_name) as f: + countries_num = json.load(f) + except (IOError, ValueError): + # use the fallback value above + pass for c, v in countries_num: print("%s.value %d" % (c, v))