Bug report
Bug description:
IDLE aborts at startup with a traceback instead of degrading gracefully when a user configuration file (~/.idlerc/config-*.cfg) cannot be parsed.
idlelib.config.IdleConfParser.Load calls configparser's read_file with no error handling, so a configparser.Error such as a MissingSectionHeaderError from a partially written file (for example one left behind by an interrupted Save) propagates out of IdleConf.LoadCfgFiles and stops IDLE from opening. The user then has to find and delete the file by hand.
The config.py module docstring states that the configuration system is meant to degrade gracefully rather than fail.
Reproduction
import os, tempfile
from idlelib import config
with tempfile.TemporaryDirectory() as d:
path = os.path.join(d, 'config-main.cfg')
with open(path, 'w', encoding='utf-8') as f:
f.write('option = value\n') # missing section header
config.IdleConfParser(path).Load()
On the main branch this raises:
configparser.MissingSectionHeaderError: File contains no section headers.
file: '.../config-main.cfg', line: 1
'option = value\n'
The same happens for a real profile inside IdleConf.LoadCfgFiles() during startup, so IDLE will not open until the file is removed.
Suggested fix
Catch configparser.Error in IdleConfParser.Load, warn to stderr, and fall back to the default configuration, matching the documented behavior.
CPython versions tested on:
3.16, CPython main branch
Operating systems tested on:
macOS
Linked PRs
Bug report
Bug description:
IDLE aborts at startup with a traceback instead of degrading gracefully when a user configuration file (
~/.idlerc/config-*.cfg) cannot be parsed.idlelib.config.IdleConfParser.Loadcallsconfigparser'sread_filewith no error handling, so aconfigparser.Errorsuch as aMissingSectionHeaderErrorfrom a partially written file (for example one left behind by an interruptedSave) propagates out ofIdleConf.LoadCfgFilesand stops IDLE from opening. The user then has to find and delete the file by hand.The
config.pymodule docstring states that the configuration system is meant to degrade gracefully rather than fail.Reproduction
On the main branch this raises:
The same happens for a real profile inside
IdleConf.LoadCfgFiles()during startup, so IDLE will not open until the file is removed.Suggested fix
Catch
configparser.ErrorinIdleConfParser.Load, warn to stderr, and fall back to the default configuration, matching the documented behavior.CPython versions tested on:
3.16, CPython main branch
Operating systems tested on:
macOS
Linked PRs