Skip to content

IDLE fails to start when the user configuration file cannot be parsed #153477

Description

@tonghuaroot

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions