Skip to content

Commit d843da5

Browse files
authored
refactor: more informative error message when an unexpected error occurred. (#218)
1 parent 3c4cbb1 commit d843da5

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
UTIL_VERSION := 0.5.13
1+
UTIL_VERSION := 0.5.14
22
UTIL_NAME := codeplag
33
PWD := $(shell pwd)
44

src/codeplag/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ def main() -> ExitCode:
3030
except KeyboardInterrupt:
3131
logger.warning("The util stopped by keyboard interrupt.")
3232
return ExitCode.EXIT_KEYBOARD
33-
except Exception:
33+
except Exception as error:
3434
logger.error(
35-
"An unexpected error occurred while running the utility. "
35+
"An unexpected error occurred while running the utility - %s. "
3636
"For getting more information, check file '%s'.",
37+
error,
3738
LOG_PATH,
3839
)
39-
logger.debug("Trace:", exc_info=True)
40+
stdout_handler = logger.handlers.pop()
41+
logger.error("Trace:", exc_info=True)
42+
logger.handlers.append(stdout_handler)
4043
return ExitCode.EXIT_UNKNOWN
4144

4245
return code

src/codeplag/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from codeplag.consts import (
77
DEFAULT_MODE,
8+
UTIL_NAME,
9+
UTIL_VERSION,
810
)
911
from codeplag.handlers.check import IgnoreThresholdWorksComparator, WorksComparator
1012
from codeplag.handlers.report import (
@@ -55,7 +57,7 @@ def __init__(self: Self, parsed_args: dict[str, Any]) -> None:
5557
self.directories: list[Path] = parsed_args.pop("directories", [])
5658

5759
def run(self: Self) -> ExitCode:
58-
logger.debug("Starting codeplag util ...")
60+
logger.info("Starting %s util (%s) ...", UTIL_NAME, UTIL_VERSION)
5961

6062
if self.root == "settings":
6163
if self.command == "show":

0 commit comments

Comments
 (0)