Skip to content

Commit 0352c4d

Browse files
author
Nikolai Lambrov
committed
Enhance error handling in Auth class for token and ID file retrieval
- Added checks to ensure the existence and non-emptiness of the token and ID files in the Auth class. This improvement raises appropriate exceptions with clear error messages when the files are missing or empty, enhancing robustness and debugging capabilities.
1 parent 8ed32d4 commit 0352c4d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

frameworks/jenkins/auth/auth.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@ def __init__(self, id: str = None, token: str = None):
1111
self.token = token or self._get_token()
1212

1313
def _get_token(self) -> str:
14-
return self.TOKEN_FILE.read_text().strip()
14+
if not self.TOKEN_FILE.is_file():
15+
raise FileNotFoundError(f"|ERROR| Token file not found: {self.TOKEN_FILE}")
16+
token = self.TOKEN_FILE.read_text().strip()
17+
if not token:
18+
raise ValueError(f"|ERROR| Token file is empty: {self.TOKEN_FILE}")
19+
return token
1520

1621
def _get_id(self) -> str:
17-
return self.ID_FILE.read_text().strip()
22+
if not self.ID_FILE.is_file():
23+
raise FileNotFoundError(f"|ERROR| ID file not found: {self.ID_FILE}")
24+
id = self.ID_FILE.read_text().strip()
25+
if not id:
26+
raise ValueError(f"|ERROR| ID file is empty: {self.ID_FILE}")
27+
return id

0 commit comments

Comments
 (0)