Skip to content

Commit 55f1ddf

Browse files
committedOct 29, 2024·
Silence error messages in Telemetry.
1 parent 4cddb7f commit 55f1ddf

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed
 

‎src/backend/backend_ga.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def send(self, message: Message):
3838
if self.backend_url.lower().startswith('http'):
3939
req = request.Request(self.backend_url, data=data)
4040
else:
41-
raise ValueError("Incorrect backend URL.")
41+
log.warning("Incorrect backend URL.")
42+
return
4243

4344
request.urlopen(req) #nosec
4445
except Exception as err:

‎src/backend/backend_ga4.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import json
55
import uuid
6+
import logging as log
7+
68
from copy import copy
79
from urllib import request
810

@@ -39,7 +41,8 @@ def send(self, message: dict):
3941
if self.backend_url.lower().startswith('http'):
4042
req = request.Request(self.backend_url, data=data)
4143
else:
42-
raise ValueError("Incorrect backend URL.")
44+
log.warning("Incorrect backend URL.")
45+
return
4346

4447
request.urlopen(req) # nosec
4548
except Exception as err:

‎src/main.py

+1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def _update_opt_in_status(tid: str, new_opt_in_status: bool):
248248
else:
249249
updated = opt_in_checker.update_result(ConsentCheckResult.DECLINED)
250250
if not updated:
251+
print("Could not update the consent file. No telemetry will be sent.")
251252
return
252253

253254
telemetry = Telemetry(tid=tid, app_name=app_name, app_version=app_version, backend='ga4')

‎src/utils/opt_in_checker.py

+24-13
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ def consent_file_base_dir():
9797
dir_to_check = Path.home()
9898

9999
if dir_to_check is None:
100-
raise Exception('Failed to find location of the openvino_telemetry file.')
100+
log.warning('Failed to find location of the openvino_telemetry file.')
101+
return None
101102

102103
consent_base_dir = os.path.expandvars(dir_to_check)
103104
if not os.path.isdir(consent_base_dir):
104-
raise Exception('Failed to find location of the openvino_telemetry file.')
105+
log.warning('Failed to find location of the openvino_telemetry file.')
106+
return None
105107

106108
return consent_base_dir
107109

@@ -116,7 +118,8 @@ def consent_file_subdirectory():
116118
return 'Intel Corporation'
117119
elif platform in ['Linux', 'Darwin']:
118120
return 'intel'
119-
raise Exception('Failed to find location of the openvino_telemetry file.')
121+
log.warning('Failed to find location of the openvino_telemetry file.')
122+
return None
120123

121124
def consent_file(self):
122125
"""
@@ -144,6 +147,9 @@ def create_or_check_consent_dir(self):
144147
:return: True if the directory is created and writable, otherwise False
145148
"""
146149
base_dir = self.consent_file_base_dir()
150+
consent_file_subdirectory = self.consent_file_subdirectory()
151+
if self.consent_file_base_dir() is None or consent_file_subdirectory is None:
152+
return False
147153
base_is_dir = os.path.isdir(base_dir)
148154
base_dir_exists = os.path.exists(base_dir)
149155
base_w_access = os.access(base_dir, os.W_OK)
@@ -155,33 +161,33 @@ def create_or_check_consent_dir(self):
155161
"Please allow write access to the following directory: {}".format(base_dir))
156162
return False
157163

158-
consect_file_dir = os.path.join(self.consent_file_base_dir(), self.consent_file_subdirectory())
159-
consent_file_is_dir = os.path.isdir(consect_file_dir)
160-
consent_file_dir_exists = os.path.exists(consect_file_dir)
164+
consent_file_dir = os.path.join(self.consent_file_base_dir(), consent_file_subdirectory)
165+
consent_file_is_dir = os.path.isdir(consent_file_dir)
166+
consent_file_dir_exists = os.path.exists(consent_file_dir)
161167

162168
# If consent path exists and it is not directory, we try to remove it
163169
if consent_file_dir_exists and not consent_file_is_dir:
164170
try:
165-
os.remove(consect_file_dir)
171+
os.remove(consent_file_dir)
166172
except:
167-
log.warning("Unable to create directory for openvino_telemetry file, as {} is invalid directory.".format(consect_file_dir))
173+
log.warning("Unable to create directory for openvino_telemetry file, as {} is invalid directory.".format(consent_file_dir))
168174
return False
169175

170-
if not os.path.exists(consect_file_dir):
176+
if not os.path.exists(consent_file_dir):
171177
try:
172-
os.mkdir(consect_file_dir)
178+
os.mkdir(consent_file_dir)
173179

174180
# check that directory is created
175-
if not os.path.exists(consect_file_dir):
181+
if not os.path.exists(consent_file_dir):
176182
return False
177183
except Exception as e:
178184
log.warning("Failed to create directory for openvino_telemetry file: {}".format(str(e)))
179185
return False
180186

181-
consent_file_w_access = os.access(consect_file_dir, os.W_OK)
187+
consent_file_w_access = os.access(consent_file_dir, os.W_OK)
182188
if not consent_file_w_access:
183189
log.warning("Failed to create openvino_telemetry file. "
184-
"Please allow write access to the following directory: {}".format(consect_file_dir))
190+
"Please allow write access to the following directory: {}".format(consent_file_dir))
185191
return False
186192
return True
187193

@@ -191,6 +197,8 @@ def update_result(self, result: ConsentCheckResult):
191197
:param result: opt-in dialog result.
192198
:return: False if the consent file is not writable, otherwise True
193199
"""
200+
if self.consent_file_base_dir() is None or self.consent_file_subdirectory() is None:
201+
return False
194202
if not os.path.exists(self.consent_file()):
195203
if not self.create_new_consent_file():
196204
return False
@@ -297,6 +305,9 @@ def check(self, enable_opt_in_dialog, disable_in_ci=False):
297305
Checks if user has accepted the collection of the information by checking the consent file.
298306
:return: consent check result
299307
"""
308+
if self.consent_file_base_dir() is None or self.consent_file_subdirectory() is None:
309+
return ConsentCheckResult.DECLINED
310+
300311
if disable_in_ci and self._run_in_ci():
301312
return ConsentCheckResult.DECLINED
302313

0 commit comments

Comments
 (0)
Please sign in to comment.