Skip to content

Commit

Permalink
добавил возможные exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
agnusarev committed Jun 16, 2024
1 parent 8a2bcfe commit 02e7e31
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/log_analyzer/log_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ def logging_decorator(func: Any) -> Any:
@functools.wraps(func)
def wrapper(*args, **kwargs): # type: ignore
try:
# log.info(f"Start {func.__name__}")
result = func(*args, **kwargs)
# log.info(f"End {func.__name__}")
return result
except KeyboardInterrupt as e:
log.error(f"KeyboardInterrupt while running {func.__name__}. exception: {str(e)}")
Expand All @@ -69,7 +67,17 @@ class LogFile:
def read_log(path: Path) -> Generator[str, None, None]:
reader: Any = gzip.open if str(path).endswith(".gz") else open

file = reader(path, mode="rt", encoding="utf-8")
try:
file = reader(path, mode="rt", encoding="utf-8")
except FileNotFoundError:
log.info(f"File {path} isn't exist.")
raise
except PermissionError:
log.info(f"File {path} cann't be read.")
raise
except OSError as e:
log.error(f"Exception raised while opening file {path}: {str(e)}")
raise
log.info(f"File {path} starting to read.")
while line := file.readline():
yield line
Expand Down

0 comments on commit 02e7e31

Please sign in to comment.