-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
gh-103606: Improve error message from logging.config.FileConfig #103628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
78182b2
2c08f30
091cfc5
467f639
6ecfad7
c75b986
deb3c3e
0f299c0
c927ac3
a9cc7c0
96a9260
1c0ce20
340b860
5fb63b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ | |
| 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') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ValueError is generally only used when the value itself is a problem, not when something external to the process such as a filesystem doesn't look right. Same below. If in doubt as to what exception to use here, I'd just go with RuntimeError if you don't have an Error exception class for your package already. |
||
|
|
||
| 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) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strictly speaking I'd have said versionchanged rather than versionadded.