diff options
author | Prince Roshan <princekrroshan01@gmail.com> | 2023-05-18 04:20:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-18 04:20:47 (GMT) |
commit | 152227b569c3a9b87fe0483706f704762ced6d75 (patch) | |
tree | 5b0eaf24758bbb4aa37ca53f7a4f40cf7cdbe034 /Lib/logging/config.py | |
parent | c5b670efd1e6dabc94b6308734d63f762480b80f (diff) | |
download | cpython-152227b569c3a9b87fe0483706f704762ced6d75.zip cpython-152227b569c3a9b87fe0483706f704762ced6d75.tar.gz cpython-152227b569c3a9b87fe0483706f704762ced6d75.tar.bz2 |
gh-103606: Improve error message from logging.config.FileConfig (GH-103628)
Diffstat (limited to 'Lib/logging/config.py')
-rw-r--r-- | Lib/logging/config.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/Lib/logging/config.py b/Lib/logging/config.py index 16c54a6..652f21e 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -29,6 +29,7 @@ import functools import io import logging import logging.handlers +import os import queue import re import struct @@ -60,15 +61,24 @@ def fileConfig(fname, defaults=None, disable_existing_loggers=True, encoding=Non """ import configparser + if isinstance(fname, str): + if not os.path.exists(fname): + raise FileNotFoundError(f"{fname} doesn't exist") + elif not os.path.getsize(fname): + raise ValueError(f'{fname} is an empty file') + if isinstance(fname, configparser.RawConfigParser): cp = fname else: - cp = configparser.ConfigParser(defaults) - if hasattr(fname, 'readline'): - cp.read_file(fname) - else: - encoding = io.text_encoding(encoding) - cp.read(fname, encoding=encoding) + try: + cp = configparser.ConfigParser(defaults) + if hasattr(fname, 'readline'): + cp.read_file(fname) + else: + encoding = io.text_encoding(encoding) + cp.read(fname, encoding=encoding) + except configparser.ParsingError as e: + raise ValueError(f'{fname} is invalid: {e}') formatters = _create_formatters(cp) |