Skip to content

Commit 77896ec

Browse files
committed
annotate.py: Make the script more resilient
Currently if you cannot create the log file, you cannot even run $ diff-annotate <subcommand> --help because it fails to create diff-annotate.log (with PermissionDenied). Wrap creating log file in try: ... except ... to make the diff-annotate script more resilient and easier to use.
1 parent 77ce606 commit 77896ec

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/diffannotator/annotate.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,11 +2564,15 @@ def common(
25642564
# common() should be called only when running it as Typer script, from app
25652565
logger = logging.getLogger()
25662566

2567-
logging.basicConfig(filename=logfile, level=logging.WARNING)
2568-
print(f"Logging to '{logfile}' file, with log level={logging.getLevelName(logger.level)}")
2567+
try:
2568+
logging.basicConfig(filename=logfile, level=logging.WARNING)
2569+
print(f"Logging to '{logfile}' file, with log level={logging.getLevelName(logger.level)}")
2570+
except PermissionError:
2571+
print(f"Warning: could not open '{logfile}' file for logging, permission denied")
25692572

25702573
if version: # this should never happen, because version_callback() exits the app
25712574
print(f"Diff Annotator version: {get_version()}")
2575+
25722576
if use_pylinguist:
25732577
if has_pylinguist:
25742578
print('Detecting languages from file name using Python clone of GitHub Linguist.')

0 commit comments

Comments
 (0)