Skip to content

Commit 49bad04

Browse files
committed
Fix client crash in case of Client ID saving error
1 parent d2449cd commit 49bad04

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Fixed
5+
- Client crash in case of Client ID saving error, by @HardNorth
46

57
## [5.3.1]
68
### Added

reportportal_client/services/client_id.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import configparser
1717
import io
18+
import logging
1819
import os
1920
from uuid import uuid4
2021

@@ -24,6 +25,9 @@
2425
RP_PROPERTIES_FILE_PATH
2526

2627

28+
logger = logging.getLogger(__name__)
29+
logger.addHandler(logging.NullHandler())
30+
2731
class __NoSectionConfigParser(configparser.ConfigParser):
2832
DEFAULT_SECTION = 'DEFAULT'
2933

@@ -64,12 +68,16 @@ def _read_client_id():
6468

6569
def _store_client_id(client_id):
6670
config = __read_config()
67-
if not os.path.exists(RP_FOLDER_PATH):
68-
os.makedirs(RP_FOLDER_PATH)
69-
config.set(__NoSectionConfigParser.DEFAULT_SECTION, CLIENT_ID_PROPERTY,
70-
client_id)
71-
with open(RP_PROPERTIES_FILE_PATH, 'w') as fp:
72-
config.write(fp)
71+
try:
72+
if not os.path.exists(RP_FOLDER_PATH):
73+
os.makedirs(RP_FOLDER_PATH)
74+
config.set(__NoSectionConfigParser.DEFAULT_SECTION, CLIENT_ID_PROPERTY,
75+
client_id)
76+
with open(RP_PROPERTIES_FILE_PATH, 'w') as fp:
77+
config.write(fp)
78+
except (PermissionError, IOError) as error:
79+
logger.exception('[%s] Unknown exception has occurred. '
80+
'Skipping client ID saving.', error)
7381

7482

7583
def get_client_id():

0 commit comments

Comments
 (0)