Skip to content

Commit 12f1581

Browse files
gh-103606: raise RuntimeError if config file is invalid or empty (#104701)
(this adjusts new code) raise RuntimeError if provided config file is invalid or empty, not ValueError.
1 parent 27a68be commit 12f1581

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Doc/library/logging.config.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ in :mod:`logging` itself) and defining handlers which are declared either in
8888
configuration).
8989

9090
It will raise :exc:`FileNotFoundError` if the file
91-
doesn't exist and :exc:`ValueError` if the file is invalid or
91+
doesn't exist and :exc:`RuntimeError` if the file is invalid or
9292
empty.
9393

9494
:param fname: A filename, or a file-like object, or an instance derived
@@ -130,7 +130,7 @@ in :mod:`logging` itself) and defining handlers which are declared either in
130130
.. versionadded:: 3.10
131131
The *encoding* parameter is added.
132132

133-
.. versionadded:: 3.12
133+
.. versionchanged:: 3.12
134134
An exception will be thrown if the provided file
135135
doesn't exist or is invalid or empty.
136136

Lib/logging/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def fileConfig(fname, defaults=None, disable_existing_loggers=True, encoding=Non
6565
if not os.path.exists(fname):
6666
raise FileNotFoundError(f"{fname} doesn't exist")
6767
elif not os.path.getsize(fname):
68-
raise ValueError(f'{fname} is an empty file')
68+
raise RuntimeError(f'{fname} is an empty file')
6969

7070
if isinstance(fname, configparser.RawConfigParser):
7171
cp = fname
@@ -78,7 +78,7 @@ def fileConfig(fname, defaults=None, disable_existing_loggers=True, encoding=Non
7878
encoding = io.text_encoding(encoding)
7979
cp.read(fname, encoding=encoding)
8080
except configparser.ParsingError as e:
81-
raise ValueError(f'{fname} is invalid: {e}')
81+
raise RuntimeError(f'{fname} is invalid: {e}')
8282

8383
formatters = _create_formatters(cp)
8484

Lib/test/test_logging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,12 +1781,12 @@ def test_exception_if_confg_file_is_invalid(self):
17811781
"""
17821782

17831783
file = io.StringIO(textwrap.dedent(test_config))
1784-
self.assertRaises(ValueError, logging.config.fileConfig, file)
1784+
self.assertRaises(RuntimeError, logging.config.fileConfig, file)
17851785

17861786
def test_exception_if_confg_file_is_empty(self):
17871787
fd, fn = tempfile.mkstemp(prefix='test_empty_', suffix='.ini')
17881788
os.close(fd)
1789-
self.assertRaises(ValueError, logging.config.fileConfig, fn)
1789+
self.assertRaises(RuntimeError, logging.config.fileConfig, fn)
17901790
os.remove(fn)
17911791

17921792
def test_exception_if_config_file_does_not_exist(self):

0 commit comments

Comments
 (0)