You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unhelpful error message from logging.config.FileConfig can be improved #103606
If a configuration file does not exist, the error raised by logging.config.fileConfig doesn't say that the file doesn't exist, instead suggesting that the file has an invalid format. This should be improved so that the correct error message is provided.
Pitch
The improved error message will guide a user to an error such as a typo in the filename more quickly. See for example this question.
@Agent-Hellboy It's an open project, no preliminary assignment is required. The only thing you need is to follow the contributor's manual at https://devguide.python.org/ where conventions and processes are described.
Wouldn't it be simpler to use e.g. os.path.exists() and then throw a FileNotFoundError if the file doesn't exist? That would be the approach I would have taken.
Yes, but the "file not found" message/FileNotFound exception are more informative than a generic "invalid file" when the file doesn't exist. It's a small point, I suppose; it's easier to ask for forgiveness, but that doesn't mean it's a cast-iron rule.
I left some comments on the merged PR... ValueError isn't the right exception to use for things external to the process not related to the variable value itself. I suggest RuntimeError if you don't have your own Error exception class.
Activity
Agent-Hellboy commentedon Apr 19, 2023
Hi, @vsajip can I try to fix this?
arhadthedev commentedon Apr 19, 2023
@Agent-Hellboy It's an open project, no preliminary assignment is required. The only thing you need is to follow the contributor's manual at https://devguide.python.org/ where conventions and processes are described.
Agent-Hellboy commentedon Apr 19, 2023
okay, sure
Agent-Hellboy commentedon Apr 19, 2023
Hi @arhadthedev
my approach would be to check the return value of
cp.read(fname, encoding=encoding)cpython/Lib/logging/config.py
Line 71 in d1e4917
It uses
configparserto parse the configuration files which suppresses the OSError but it returns an empty list if the file is not presentcpython/Lib/configparser.py
Line 665 in d1e4917
I will raise a PR which will raise ValueError that the file is not present and will try to include a test for the same
pythongh-103606: Improve error message from logging.config.FileConfig
vsajip commentedon Apr 20, 2023
Wouldn't it be simpler to use e.g.
os.path.exists()and then throw aFileNotFoundErrorif the file doesn't exist? That would be the approach I would have taken.arhadthedev commentedon Apr 20, 2023
Because of the easier to ask for forgiveness than permission principle with the very
os.path.exists()as an example:vsajip commentedon Apr 20, 2023
Yes, but the "file not found" message/
FileNotFoundexception are more informative than a generic "invalid file" when the file doesn't exist. It's a small point, I suppose; it's easier to ask for forgiveness, but that doesn't mean it's a cast-iron rule.Agent-Hellboy commentedon Apr 20, 2023
okay, I will raise FileNotFound before giving the file to the config parser
cpython/Lib/logging/config.py
Line 63 in 6be7aee
why should I try to parse a file which is not presentpythongh-103606: Improve error message from logging.config.FileConfig
gh-103606: Improve error message from logging.config.FileConfig (GH-1…
pythongh-103606: Improve error message from logging.config.FileConfig (…
gpshead commentedon May 20, 2023
I left some comments on the merged PR... ValueError isn't the right exception to use for things external to the process not related to the variable value itself. I suggest RuntimeError if you don't have your own Error exception class.
Agent-Hellboy commentedon May 20, 2023
sure @gpshead, I will raise a PR
pythongh-103606: raise RuntimeError if provided config file is invali…
gh-103606: raise RuntimeError if config file is invalid or empty (#10…
[3.11] gh-103606: Improve error message from logging.config.FileConfig (
gpshead commentedon May 21, 2023
thanks!